-
Couldn't load subscription status.
- Fork 1.4k
LogLevel config #7937
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
LogLevel config #7937
Conversation
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.
Looks good! Just a couple of comments.
| val Trace: LogLevel = LogLevel(0, "TRACE", 7) | ||
| val None: LogLevel = LogLevel(Int.MaxValue, "OFF", 7) | ||
|
|
||
| val config: Config[LogLevel] = Config.string.mapOrFail { value => |
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.
I think this should probably be in the Config companion object. Organizing principle would be configurations for all ZIO and standard library data types are in the Config companion object, and all other configurations are defined in the companion object of the data type.
| } | ||
| } | ||
|
|
||
| val logLevelMapping: Map[String, LogLevel] = Map( |
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.
We should make this private.
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.
i did not make it private, as it can be used in zio-logging to get all LogLevel values and for similar cases,
but we can find some alternative ...
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.
Better to make LogLevel.levels expose all log levels.
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.
👍
| case NonFatal(e) => Left(Config.Error.InvalidData(Chunk.empty, s"Expected a local time value, but found ${text}")) | ||
| } | ||
| } | ||
| case object LogLevelType extends Primitive[LogLevel] { |
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.
We should not introduce additional primitives here.
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.
should it be just
def logLevel: Config[LogLevel] = Config.string.mapOrFail { value =>
LogLevel.logLevelMapping.get(value.toUpperCase) match {
case Some(v) => Right(v)
case None => Left(Config.Error.InvalidData(Chunk.empty, s"Expected a log level, but found ${value}"))
}
}?
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 looks fine.
| LogLevel.None | ||
| ) | ||
|
|
||
| private[zio] val levelMapping: Map[String, LogLevel] = levels.map(level => (level.label, level)).toMap |
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.
I think we can just inline this into the implementation of Config.logLevel at this point.
levels.collectFirst { case logLevel if logLevel.label == value.toUpperCase => ??? }| LogLevel.Error.label -> LogLevel.Error, | ||
| LogLevel.Fatal.label -> LogLevel.Fatal, | ||
| LogLevel.None.label -> LogLevel.None | ||
| val levels: Chunk[LogLevel] = Chunk( |
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 should possibly just be a set.
added configuration for
LogLevel