outr / scribe

The fastest logging library in the world. Built from scratch in Scala and programmatically configurable.
MIT License
525 stars 42 forks source link

Slack module not working? #639

Closed KristianAN closed 1 day ago

KristianAN commented 5 days ago

I can't get the slack module to work, however testing the slack hook with curl works fine for the same hash

Looking at the source in scribe I am a bit confused as to how this is supposed to work? Looking at the writer I can't see how it would actually ever write?

class SlackWriter(slack: Slack, emojiIcon: String) extends Writer {
  override def write(record: LogRecord, output: LogOutput, outputFormat: OutputFormat): Unit = slack.request(
    message = output.plainText,
    emojiIcon = emojiIcon
  )
}

slack.request returns an cats.effect.IO. Meaning write returns unit not because of any unit computation but because we have a discarded non unit value. It seems to me that the options here are to either call unsafeRunAndForget or to also have an IO writer that can be wired up in the application somehow.

Creating my own SlackWriter as such

  class MySlackWriter(slack: Slack, emojiIcon: String) extends Writer {
    import cats.effect.unsafe.implicits.global
    override def write(
        record: LogRecord,
        output: LogOutput,
        outputFormat: OutputFormat
    ): Unit = slack
      .request(
        message = output.plainText,
        emojiIcon = emojiIcon
      ).unsafeRunAndForget()

  }

and overwriting the writer for the root logger works and it now sends messages again. Using unsafeRun is a bit icky, so having an effectful writer would be preferred, but I am guessing that might take significant work?

darkfrog26 commented 4 days ago

It has been a long time since I touched the Slack code. It's possible a refactoring screwed this up. I agree that unsafe run is icky, but if you're interested in submitting a PR, I can merge it.

darkfrog26 commented 1 day ago

@KristianAN please see 3.15.1 release: https://github.com/outr/scribe/releases/tag/3.15.1