-
Notifications
You must be signed in to change notification settings - Fork 82
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
LogAnnotation does not work with newtypes #451
Comments
it is look like, it is also related to zio/zio-prelude#821 and zio/izumi-reflect#309 |
may be related to zio/zio-prelude#949 |
new zio prelude package zio.logging.example
import zio.logging.{LogAnnotation, LogFormat, consoleJson}
import zio.prelude.Newtype
import zio.{ExitCode, Runtime, Scope, ZIO, ZIOAppDefault, _}
import java.util.UUID
object ConsoleJsonApp extends ZIOAppDefault {
object UserType extends Newtype[UUID]
type UserType = UserType.Type
private val userLogAnnotation = LogAnnotation[UserType]("user", (_, i) => i, _.toString)
private val logger =
Runtime.removeDefaultLoggers >>> consoleJson(
LogFormat.default + LogFormat.annotation(LogAnnotation.TraceId) + LogFormat.annotation(
userLogAnnotation
)
)
private val users = List.fill(2)(UUID.randomUUID())
override def run: ZIO[Scope, Any, ExitCode] =
(for {
traceId <- ZIO.succeed(UUID.randomUUID())
_ <- ZIO.foreachPar(users) { uId =>
{
ZIO.logInfo("Starting operation") *>
ZIO.sleep(500.millis) *>
ZIO.logInfo("Stopping operation")
} @@ userLogAnnotation(UserType(uId))
} @@ LogAnnotation.TraceId(traceId)
_ <- ZIO.logInfo("Done")
} yield ExitCode.success).provide(logger)
}
|
LGTM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trying to use newtypes with
LogAnnotation
but you get compile errors.Using zio 2.0.0-RC5, zio-prelude 1.0.0-RC13, zio-logging-slf4j 2.0.0-RC8.
example
error
The text was updated successfully, but these errors were encountered: