Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Fatal exceptions are not logged #7

Open
mtomko opened this issue Mar 15, 2016 · 0 comments
Open

Fatal exceptions are not logged #7

mtomko opened this issue Mar 15, 2016 · 0 comments

Comments

@mtomko
Copy link

mtomko commented Mar 15, 2016

This is perhaps due to the threaded/asynchronous nature of the journal library, but fatal exceptions are not logged unless they are handled specially. This issue may be more one of documentation, as a workaround exists, but it may be worth investigating whether it would be possible to deal with the problem so the workaround was not necessary.

To reproduce this issue with 2.2.1, run:

import journal._

object RapidDeath extends App {

  val log = Logger[this.type]

  try {
    throw new Exception("Oh no!")
  } catch {
    case t: Throwable => log.error("Died", t)
  }

}

No log file is written, perhaps because the application terminates (along with the logger threads) before any buffers are flushed and a message is written.

Conversely, you can ensure that the exception will be logged with:

import journal._

object RapidDeath extends App {

  val log = Logger[this.type]

  try {
    throw new Exception("Oh no!")
  } catch {
    case t: Throwable => log.backend.error("Died", t)
  }

}

Note the direct call to log.backend in the catch block. This appears to bypass the threading, ensuring the message reaches the log before the application terminates. I think this is mostly a reasonable workaround, so long as your application is sufficiently simple to have just one or two places where this specialized try/catch/log behavior is necessary, but it might merit a note in the documentation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant