Logging System¶
Strix has its own logging system. Strix classes use them to log what happened inside the SDK. You can also use the Strix logging system to log events from your own scripts.
The logging system is controlled by the LogManager
singleton.
Note
Strix’s logging classes and value types resides in the namespace SoftGear.Strix.Net.Logging
.
You will need to add the following using
directive to use the Strix logging system.
using SoftGear.Strix.Net.Logging;
Log Level¶
During development and debugging,
it can be useful to raise the log level of debug messages.
In order to do this, change the value of LogManager.Instance.Filter
.
It is an enum of type Level
,
and the available options (ordered from less severe to more severe) are as follows:
Name |
Logged events |
TRACE |
Specific, detailed steps of functions |
DEBUG |
Information useful for error debugging |
INFO |
Normal application behavior information |
WARNING |
Unexpected behavior |
ERROR |
Non-fatal errors |
FATAL |
Fatal errors |
Note
As in other logging systems, if you set Filter
to a particular log level,
all events that are more severe than the specified level are also logged.
Logs from your scripts¶
You can not only filter the messages from the SDK
but also use Logger
class to output your own messages,
and they will be filtered as well.
There are several Logger
instances,
which are categorized in the nature of logs.
To log your own messages,
you first have to get an appropriate logger for use.
Each logger is identified by a name,
and you can use the following method of LogManager
to get one.
bool FindLogger(string name, out Logger logger)
You can find available loggers by calling GetLoggers()
as follows:
var availableLoggerNames = LogManager.Instance.GetLoggers().Keys;
Most useful loggers for your own scripts are perhaps “StrixBehaviour” and “StrixReplicator”.
After you’ve received the logger reference, you can use it to output messages to the log:
// string
logger.Warning("Something bad happened.");
// delegate
public string MyLoggingFunc()
{
return "Something bad happened.";
}
logger.Warning(MyLoggingFunc);
Note that the Logger
has methods other than Warning
whose names correspond to available log levels.
You can also use the Log
method that takes a level as an argument.
logger.Log(Level.WARNING, "Something bad happened");
logger.Log(Level.WARNING, MyLoggingFunc);
Checking a log level¶
Logger
has another useful method to check if some specific log level is currently enabled.
bool IsLogEnabled(Level logLevel)
if (logger.IsLogEnabled(Level.DEBUG))
foreach (var node in searchResult.Result.GetModelCollection())
logger.Debug("Node " + node.GetUid() + " " + node.GetHost() + ":" + node.GetPort() + " " + node.GetProtocol() + " " + node.GetNodeType());