Last updated

Logging

Logging is an essential aspect of software development, as it allows developers to track and debug issues that arise during the applications's runtime. The Python SDK provides logging capabilities that enable developers to analyse application events and errors.

To use the SDK, include the Nuget package and add the following statement to the C# source.

using static Agora.SDK;

Log Levels

The SDK provides the following log levels:

TRACE
DEBUG
INFO
WARN
ERROR
FATAL
HEADING
EXCEPTION

All LogLevels except Info, Trace, and Warning will record source code location to ease troubleshooting.

Example

logger.info("Hello World!");

produces:

I(99) - Hello World!

Each message begins with the first letter of the LogLevel, such as T - Trace, D - Debug, I - Info and so on, followed by the number of milliseconds since the application started, in parentheses.

A singleton logger object of type AgoraLogger is provided by the SDK and is imported as shown:

from agoraiot import logger

Logging can be done either by invoking the correct method of logger directly with desired log level, or using methods for each of the logging levels as shown below.

from agoraiot import logger, LogLevel
logger.write(LogLevel.TRACE, "trace message")

or

logger.info("info message")
logger.trace("trace message")
logger.debug("debug message")
logger.warn("warning message")
logger.error("error message")
logger.fatal("fatal message")
logger.heading("heading message")
ex=Exception("An Exception of Some Sort")
logger.exception(ex, "exception message")

The logger also supports the following methods:

  • set_level(LogLevel level)

    Allows the programmatic setting of the logging level, overriding the default set in the AEA.config.json file.

  • write(LogLevel level, str Message)

    Writes a message to the log. The memberName, sourceFilePath, and sourceLineNumber are not used if the LogLevel is Info, Warn, or Fatal.

  • heading(str Message)

    Writes a heading message to the log at LogLevel.Info. This method helps to find sections in the LogTarget by placing the Heading on the right side of the text.

  • exception(Exception exception, str Message, LogLevel level=LogLevel.WARN)

    Writes an exception message to the log and all InnerExceptions.


Configurable Logging Settings

  • AEA2:LogLevel (string) - [optional] One of ("Trace", "Debug", "Info" (default), "Off"). This setting is not case sensitive and provides the capability to specify the minimum level of log statements included in the log. This setting affects all Logging Targets contained by the Logger.
  • AEA2:LogColoring (bool) - [optional] If 'true' colored logging is enabled. This feature is useful when using the raw logs which, when colored, includes ANSI escape sequences that can be difficult to read.

Example:

AEA.json for Logging:

{
  "Name": "DemoApp",
  "AEA2": {
    "LogLevel": "Debug",
    "LogColoring": true
    }
}