Managing logs

For monitoring or debugging your node, the Klayr SDK v6 tracks all activities that occur within the node by creating applicable log messages.

These log messages are grouped in different log levels. Hence, making it straightforward and easy to define the level of the log details.

Log levels

Log Level Description

None

No events are logged.

Fatal(60)

The node is going to stop or become unusable. This requires the operator to investigate the problem.

Error(50)

Fatal for a particular request, however the node continues servicing other requests. This also requires the operator to investigate the problem, although it does not necessarily require immediate attention.

Warn(40)

A warning indication that should be investigated eventually.

Info(30)

Detail on a regular operation.

Debug(20)

Anything else, i.e. too verbose to be included in info level.

Trace(10)

Logging from external libraries used by your node, or otherwise very detailed application logging.

To change the node log level, update the logLevel property in the config.json file, under system.logLevel as listed in the snippet below.

system options in config.json
system: {
  dataPath: '~/.klayr/beta-sdk-app',
  version: '0.1.0',
  keepEventsForHeights: 300,
  logLevel: 'info',
  enableMetrics: false,
  backup: {
    height: 0,
  },
}

Logging destination

The output sources for the logs is the console log stream. This output source can be configured independently inside of config.json as shown in the code snippet above under the options for the logger component.

Console log stream

The console log level displays the logs directly to the console from where the Klayr SDK process is started. This is useful for quick debugging or verifying that the Klayr SDK starts correctly. The default log level for the console log stream is none.

To display the console log stream, start the application as shown below:

./bin/run start  (1)
1 Pretty-prints console logs with log level equal or higher to the console log level.

Logging to a file

All log file support has been removed from the Klayr SDK as the application stdout output can be simply output to a file by a user as required. For example, on Ubuntu and MacOS you can already use the CLI options to output to a file as shown below.

./bin/run start  > app.log # will output stdout to a file app.log

To output stderr to a file run the following command.

./bin/run start  &> app.log

To output to the console log as well as writing to a file (appending mode), run the following command.

./bin/run start >&1 | tee app.log

A user can control the log level of the application using system.logLevel and as previously mentioned logging to a file is now outside of Klayr SDK.