Logging API and performance considerations

GreyCat allows you to log messages at different levels of information. Unlike other programming language, this native construction id compiled to face big data requirements. For instance there is no penalty to use extensively log trace during dev or debug phases. In production GreyCat simply removes all overhead, even the log string line construction.

The following functions allow you to log a message, at the desired granularity.

fn main() {
  var k = -12;
  trace("k == ${k}");
  if (k < 0) {
    error("${k} negative");
    return;
  }
  info("done");
}

Runtime usage

At build time, GreyCat will interpret the chosen logging granularity greycat build --log=info.

In dev mode this parameter can be used without intermediate build : greycat run --log=info.

By default, GreyCat logs messages at the info level: error(), warn(), info(), the sample above prints the following:

TRACE 2023-11-10T13:49:18.260666+00:00 0/0 log.main "k == -12"
ERROR 2023-11-10T13:49:18.260678+00:00 0/0 log.main "-12 negative"

For performance reason, GreyCat can’t apply the log level dynamically, it is therefore recommended to ship two project.gcp version in production if verbose mode is required.