Open ggwpez opened 3 years ago
Hi @ggwpez
I was also facing the similar problem of not being able to multiple parties apart by looking at the logs. I like your idea of using prefix
over field
. However, I am not sure if the approach you are considering will work in the following scenarios (as in case of perun-node
):
client.New
derives the logger internally from the log package.One possible solution I could see to address this aspect is to explicitly pass a logger instance to the client.New
API.
This was mainly aimed for internal logging, since we often use hierarchical loggers there.
You can already set a logger which will be used by client.New
with log.Set
. Here is an example. It should best be done in an init()
function.
If you only want to set the log-level, log/logrus.Set
is enough. @manoranjith
I do set the logger for the go-perun framework this way. Still my understanding is that, when I create two instances of the client within a single instance of the node, then both clients will be using the same logger.
Does your suggestions imply that I will be able to set different logger instances for each of the client instance ? @ggwpez
Because, when same instance of logger is used, I see no possibility to tell the which log entries corresponding to which client instance.
Now i understood what you mean. You could call log.Set
multiple times, but this is ugly.
go-perun does currently not have a straightforward way to do this.
Type IMPROVEMENT
Affects
[log]
Current situation
It is often difficult to tell multiple parties apart in the log output.
For example we have
Alice
s logger:log.WithField("role", "Alice").Info("test")
which produces:
INFO[0000] test role=Alice
Suggestion
I suggest to add a
WithPrefix(string)
function, such that the above would becomelog.WithPrefix("Alice").Info("test")
which produces:INFO[0000] Alice: test
Recursively it would look like this:
log.WithPrefix("Alice").WithPrefix("client").Info("test")
:INFO[0000] Alice.client: test
orINFO[0000] Alice: client: test
To simplify the above, a
WithPrefixes([]string)
orWithPrefices([]string)
should be added.Justification Logs are more readable with a prefix and the entity that does the logging is not a real
Field
in the first place.