Logrus: Add ability to set prefix, or set some fields to be displayed before the others in TextFormatter

Created on 20 Jun 2018  路  3Comments  路  Source: sirupsen/logrus

Having the ability to set a common prefix to a set of logged lines can be useful to visually group several lines together in a log file. The standard log package has a SetPrefix function that is quite useful.

Perhaps logrus should support the same function for parity with the log package.

Perhaps instead logrus should use the notion of fields it has, and a field could be configured to be shown before the message. This way, the information is both categorized as a field and also visually grouping similar log lines together by being first in line.

enhancement question

Most helpful comment

I didn't see the first message, but yes, prefix order answers completely the use case.

There is one catch though, logrus is marketed as API compatible with the standard library logger and the lack of prefix function makes it incompatible. It surprised me the first time because I assumed it was completely compatible.

In any case, it cannot be completely compatible, because a logrus logger will never fit in a *log.Logger type. A pity that the standard logger package doesn't use an interface type.

All 3 comments

Would not

logrus.WithField("prefix", "prefix value").Info("blabla")

answer this use case ?

Regarding the field order, this issue is already opened #770

No feedback, closing this issue as #770 is expected to meet the needs.

I didn't see the first message, but yes, prefix order answers completely the use case.

There is one catch though, logrus is marketed as API compatible with the standard library logger and the lack of prefix function makes it incompatible. It surprised me the first time because I assumed it was completely compatible.

In any case, it cannot be completely compatible, because a logrus logger will never fit in a *log.Logger type. A pity that the standard logger package doesn't use an interface type.

Was this page helpful?
0 / 5 - 0 ratings