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

Logging stderr #518

Closed
sbushmanov opened this issue Sep 27, 2023 · 2 comments
Closed

Logging stderr #518

sbushmanov opened this issue Sep 27, 2023 · 2 comments

Comments

@sbushmanov
Copy link

A newbie question here.

Suppose I have:

import scribe._
import scribe.file._

class MyClass {

    Logger.root
      .clearHandlers()
      .clearModifiers()
      .withHandler(minimumLevel = Some(Level.Info))
      .withHandler(writer = new FileWriter("./log.txt"))
      .replace()
    
    doSomething()
    
    def doSomething(): Unit = {
        scribe.info("I did something!")
        val x = 1/0
    }
}

How will I capture and redirect to log file the stderr (exception in this case)?

@darkfrog26
Copy link
Contributor

The easiest solution is just to call:

Logger.system.redirect()

That will redirect System.out and System.err to be logged.

@sbushmanov
Copy link
Author

Thank you very much, really appreciate your help!

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

No branches or pull requests

2 participants