Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@justcoon
Copy link
Contributor

added configuration for LogLevel

Copy link
Contributor

@adamgfraser adamgfraser left a 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 =>
Copy link
Contributor

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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 ...

Copy link
Member

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.

Copy link
Contributor

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] {
Copy link
Contributor

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.

Copy link
Contributor Author

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}"))
    }
  }

?

Copy link
Contributor

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
Copy link
Contributor

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(
Copy link
Contributor

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.

@adamgfraser adamgfraser merged commit b883020 into zio:series/2.x Mar 23, 2023
@justcoon justcoon deleted the loglevel_config branch April 8, 2023 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants