Skip to content
Jas edited this page Aug 24, 2018 · 8 revisions

Log - Console Logger

This library is inspired by Java's log4j and similar logging systems providing a simple console logger with the following features:

  • Consistent logging information
  • Configurable log level support from TRACE to FATAL
  • Log coloring at warning and error levels

Log Format

The library uses a standard logging format for each line that is printed to the terminal:

  • UTC date and time (.z.d and .z.t)
  • Log level (one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL)
  • Process identifier (pid-*pid*)
  • Current user (.z.u)
  • Current handle (.z.w)

An example informational message

q) .log.info "An info message"
2017.03.06 15:23:41.453 INFO pid-14448 jasra_000 0 An info message

Changing Log Levels

By default when the log library is initialised, it defaults to INFO. If the process is started in debug mode, which is defined by using the -e command line argument, the level is set to DEBUG.

The configured log level is printed when the library is initialised:

Logging enabled [ Level: INFO ]

You can use .log.setLevel to change it as necessary post initialisation.

Enabling Color Logging

When log coloring is enable, the log level is highlighted for WARN, ERROR and FATAL messages to make it easier to see.

It can be enabled in one of 2 ways:

  • Set an environment variable KDB_COLORS
  • Pass -logColors as a command line argument into the process

Color output looks as follows:

log.q Color Output

Changing Process Identifier

By default, the process is identified by its PID, in the form pid-*pid*. However, you can change it any point to be more descriptive by setting .log.process:

q) .log.info "Hi"

q).log.info "Hi"
2018.08.24 15:36:02.709 INFO pid-87646 jrajasansir 0 Hi
q) .log.process:`myProcess
q) .log.info "Hi again"
2018.08.24 15:36:31.161 INFO myProcess jrajasansir 0 Hi again
Clone this wiki locally