Skip to content
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

Add log (based on slf4j) operator #41

Closed
geminicaprograms opened this issue Nov 2, 2023 · 3 comments · Fixed by #170
Closed

Add log (based on slf4j) operator #41

geminicaprograms opened this issue Nov 2, 2023 · 3 comments · Fixed by #170
Assignees

Comments

@geminicaprograms
Copy link
Contributor

No description provided.

@adamw
Copy link
Member

adamw commented Jul 1, 2024

To consider: implement as logAsView using mapAsView

@micossow
Copy link
Contributor

micossow commented Jul 1, 2024

Some questions/discussion starters:

  1. How to manage slf4j dependency?

    1. make ox.core depend on slf4j
    2. add slf4j as "provided" dependency of ox.core (then users would need to add slf4j themselves in order to use .log operators
    3. create logging abstraction in ox.core and create a new module - ox.slf4j-logger, that would provide an implementation. Similar to org.apache.pekko.event.LoggingAdapter
    4. other?
  2. Handling logging level

    1. fixed default
    2. optional level with configurable default (via system property or something)
    3. other?
  3. Api proposal

  enum LogLevel:
    case Trace, Debug, Info, Warn, Error

  def log(name: String, level: LogLevel = LogLevel.Info, formatter: T => String = _.toString)(using Ox, StageCapacity): Source[T] =
    val logger = org.slf4j.LoggerFactory.getLogger(name)
    map(t => { logF(logger, level)(formatter(t)); t })

  def logAsView(name: String, level: LogLevel = LogLevel.Info, formatter: T => String = _.toString)(using Ox, StageCapacity): Source[T] =
    val logger = org.slf4j.LoggerFactory.getLogger(name)
    mapAsView(t => { logF(logger, level)(formatter(t)); t })

  private def logF(logger: org.slf4j.Logger, level: LogLevel): String => Unit =
    level match
      case LogLevel.Trace => logger.trace
      case LogLevel.Debug => logger.debug
      case LogLevel.Info  => logger.info
      case LogLevel.Warn  => logger.warn
      case LogLevel.Error => logger.error

@adamw
Copy link
Member

adamw commented Jul 1, 2024

To be honest I don't like neither of the options in 1., maybe since we already have .mapAsView, the simplest solution would be to add .tapAsView and document how this can be used for logging?

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 a pull request may close this issue.

3 participants