From 98b87e1e1378754a70f4d8b2f5ec27a1e0048214 Mon Sep 17 00:00:00 2001 From: Chord Date: Tue, 19 Jul 2016 03:02:44 -0400 Subject: [PATCH] Improve server logging and manually load logback --- .gitignore | 5 +++++ logback.xml | 27 +++++++++++++++++++++++++ pslogin/src/main/scala/PsLogin.scala | 30 ++++++++++++++++++++++++---- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 logback.xml diff --git a/.gitignore b/.gitignore index c415faca..76adba41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +# Project crap target *.class .idea/ @@ -7,8 +8,12 @@ out/ *.iws *.ipr *.iml + +# Random *.swp /*.csv + +# Binary files *.so *.dll *.exe diff --git a/logback.xml b/logback.xml new file mode 100644 index 00000000..b80e92e5 --- /dev/null +++ b/logback.xml @@ -0,0 +1,27 @@ + + + + + [%highlight(%5level)] %logger{35} - %msg%n + + + + + pslogin-debug.log + + + %date{ISO8601} %-5level %X %logger{35} - %msg%n + + + + + + + + + + + diff --git a/pslogin/src/main/scala/PsLogin.scala b/pslogin/src/main/scala/PsLogin.scala index 3a315cfc..9e87e745 100644 --- a/pslogin/src/main/scala/PsLogin.scala +++ b/pslogin/src/main/scala/PsLogin.scala @@ -3,6 +3,8 @@ import java.net.InetAddress import akka.actor.{ActorSystem, Props} import ch.qos.logback.classic.LoggerContext +import ch.qos.logback.classic.joran.JoranConfigurator +import ch.qos.logback.core.joran.spi.JoranException import ch.qos.logback.core.status._ import ch.qos.logback.core.util.StatusPrinter import com.typesafe.config.ConfigFactory @@ -24,6 +26,7 @@ object PsLogin { println(ansi().fgBright(MAGENTA).a(""" / ___/\ \/ _// _ \/ __/ -_) |/ / -_) __/""")) println(ansi().fgBright(RED).a("""/_/ /___/_/ \___/_/ \__/|___/\__/_/""").reset()) println(""" Login Server - PSForever Project""") + println(""" http://psforever.net""") println } @@ -57,17 +60,36 @@ object PsLogin { statusUtil.getHighestLevel(0) >= Status.WARN } - def main(args : Array[String]) : Unit = { - banner() - println(systemInformation) - + /** Loads the logging configuration and starts logging */ + def initializeLogging(logfile : String) : Unit = { // assume SLF4J is bound to logback in the current environment val lc = slf4j.LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext] + try { + val configurator = new JoranConfigurator() + configurator.setContext(lc) + + // reset any loaded settings + lc.reset() + configurator.doConfigure(logfile) + } + catch { + case je : JoranException => ; + } + if(loggerHasErrors(lc)) { + println("Loading log settings failed") StatusPrinter.printInCaseOfErrorsOrWarnings(lc) sys.exit(1) } + } + + def main(args : Array[String]) : Unit = { + // Early start up + banner() + println(systemInformation) + + initializeLogging("logback.xml") /** Initialize the PSCrypto native library *