Skip to content

Instantly share code, notes, and snippets.

@ShaneDelmore
Created August 5, 2016 04:58
Show Gist options
  • Save ShaneDelmore/d53496a7d31be5c1ead82b12bbe40b5b to your computer and use it in GitHub Desktop.
Save ShaneDelmore/d53496a7d31be5c1ead82b12bbe40b5b to your computer and use it in GitHub Desktop.
Singleton logger instead of extending ClassLogging everywhere you log
//Depends on https://github.com/nestorpersist/logging
import java.net.InetAddress
import akka.actor.ActorSystem
import com.persist.logging.{ ClassLogging, Logger, LoggingSystem }
/**
* The purpose of this object is to provide a shared logger for use throughout the program
* To use instead of mixing ClassLogging into a class use the following import:
* import TheLogger.{ logInstance => log }
*/
object TheLogger extends ClassLogging {
private val logSystem = ActorSystem("Logging")
private val logHost = InetAddress.getLocalHost.getHostName
//Needed to initialize the logging system, logs won't be generated if this is not called
private val testLoggingSystem: LoggingSystem = LoggingSystem(logSystem, "MyService", "1", logHost)
//Expose protected log by giving it a new name
lazy val logInstance: Logger = log
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment