Logrus: Add possibility to create default Fields.

Created on 15 Nov 2016  路  5Comments  路  Source: sirupsen/logrus

There are many things, what must be in every entry. For example appname or hostname.
This can be added to Logger or to Formatters. I think modify Formatters is better decision.

Most helpful comment

The problem is that with the current implementation you can't add default fields to the standard logger.

All 5 comments

I've had similar thoughts, and used this functionality in other loggers (in other languages). I'll look into this once my current PR is merged.

Does passing around a logrus.FieldLogger not satisfy this requirement?

@PurpureGecko Do you have a proposed design? PR?

Actually, this is fairly easily done by passing around a log.Entry populated with the fields:

logger := logrus.WithField("default", "foo")
logger.Info("will have default")

This has been sufficient in a number of applications. You can even store the logger in a context to make it accessible in cross-cutting areas.

Closing this. If this is insufficient, please propose a solution with a PR.

The problem is that with the current implementation you can't add default fields to the standard logger.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oconnor663 picture oconnor663  路  3Comments

penhauer-xiao picture penhauer-xiao  路  4Comments

rogierlommers picture rogierlommers  路  5Comments

anotherGoogleFan picture anotherGoogleFan  路  3Comments

demizer picture demizer  路  4Comments