wego

GoLang Micro Services Framework

View on GitHub

WeGO Logging

The WeGO logger uses zap to perform logging at the following levels:

All messages above Info level will be written to New Relic as well. So please use Info level with caution to avoid clutter.

Fields

All logging is performed in JSON. The logging level, message and time stamp are available using the following JSON fields:

Additionally, the log system also creates additional fields from the context. Hence context is mandatory. The list of fields created using context include the following:

Sinks

Currently, logging is done to stdout and all errors are printed to stderr. These logs need to be collected and sent to one consolidated log. This must be achieved during deployment. In development mode logs get printed to the console.

Additional Log fields

The following fields are also enabled or disabled as per configuration:

Signatures

To optimize log performance and to enhance usability, the following signatures are supported for each logging level. This is shown for Info level below but is applicable to other levels as well.

    func Infof(ctx context.Context, message string, args ...interface{})
    func Info(ctx context.Context, message string)
    func InfoWithFieldsf(ctx context.Context, fields map[string]string,message string, args ...interface{})
    func InfoWithFields(ctx context.Context,fields map[string]string,  message string)

A few observations about the signatures above:

  1. Context is mandatory for logging. Context must be passed around. If context is not available (such as during) startup, please use context.Background()
  2. Message is the logging message
  3. args are printf style args supported in the signatures that end with f.
  4. The WithFields signature allows custom fields to be logged using a string map. This can be useful in machine parsing of logs and is strongly encouraged.

Configurations

The configuration system allows the logging to be configured. Some of them are mentioned above (see the section on additional fields above). Here is a full list of applicable logger configurations:

There are some more configurations such as the ones below: