evolution-gaming / derivation

Configured derivation library for scala 3
MIT License
34 stars 6 forks source link

logstage derivation module #85

Open road21 opened 1 year ago

road21 commented 1 year ago

This pull request provides basic support for derivation LogstageCodec from izumi.logstage library.

Quick example:

@SnakeCase
@Discriminator("type")
enum User derives Config, EvoLog:
  case AuthorizedClient(@Rename("client_id") id: Long, name: String, @Masked token: String)
  case Anonymous

import logstage.IzLogger
val logger = IzLogger()
val user = User.AuthorizedClient(100, "Bob", "123")

import evo.derivation.logstage.instances.given // arggh
logger.trace(s"User: $user")

Will print:

T 2023-06-08T18:45:34.795 (LogstageTest.scala:27)  …ation.logstage.LogstageTest [1:main] User: user={type: authorized_client; client_id: 100; name: Bob; token: ***masked***}

The problem is that LogstageCodec is contravariant, so EvoLog doesn't extend LogstageCodec, and that's why import evo.derivation.logstage.instances.given here.