-
Notifications
You must be signed in to change notification settings - Fork 78
Allows to "pass in a logger" rather than using the customizable String->Logger func #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| /// At what level should the library actually log and print logs // TODO: We'd want to replace this by proper log handlers which allow config by labels | ||
| public var defaultLevel: Logger.Level = .info // TODO: maybe remove this? should be up to logging library to configure for us as well | ||
| public var logLevel: Logger.Level { // TODO: deprecate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe... not sure tbh.
When using the "globally set up one" this is useful since one can just set the level easily.
|
|
||
| /// Optionally override Logger that shall be offered to actors and the system. | ||
| /// This is used instead of globally configured `Logging.Logger()` factories by the actor system. | ||
| public var overrideLoggerFactory: ((String) -> Logger)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is replaced by allowing to pass in the "base logger"
| var metadata: Logger.Metadata { | ||
| [ | ||
| "swim/membersToPing": "\(self.membersToPing)", | ||
| "swim/membersToPing": Logger.Metadata.Value.array(self.membersToPing.map { "\($0)" }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provides a nicer printout in our metadata aware LogCapture
| } | ||
| } | ||
|
|
||
| return valueDescription |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small improvement while I was in here, easier to look at nested metadatas now in the LogCapture
|
|
||
| if self.captureLogs { | ||
| settings.logging.overrideLoggerFactory = capture.loggerFactory(captureLabel: name) | ||
| settings.logging.logger = capture.logger(label: name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the "main" change I guess; we no longer do the override factory but pass in a logger than can be a specific one.
FYI @weissi
|
FYI @budde, with this change it'll be possible to directly "set" the "base" logger on an actor system. |
=log readjust where LoggerWithSource makes sense - not everywhere
Motivation:
system.settings.logging.overrideLoggerFactoryso we've always thought about this, but other teams really like to "pass in a logger" which here becomes a bit weird.This allows the following patterns, while keeping all our functionality about LogCapture and similar.
Tons of discussions with @weissi led to this current rehash of how we create loggers.
We do not inherently depend on the
sourceaddition, but there are some spots where it would be the right thing:We would not use "source" for actor paths through as those we do want to "inherit" when we'd call some other library, so it has to be a Logger and not a LoggerWithSource.
This rehash allows for the following pattern:
This logger is used as "template" to create new loggers in the entire system; an actor's logger is a copy of this logger + its actor specific (e.g. path) metadata set when the actor is created.
Modifications:
Removes
In favor of
which users may change.
Result:
actor/pathmetadata, nowhere else (they used to be in the label as well, but that was slightly wrong semantically)