bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
commit 836d7b251c9e4bc41d01b6aecd8141ee570703dc parent b0a15a8b73dc103efdd8f1bef04f2a3dd0031b41 Author: Jul <jul@9o.is> Date: Thu, 7 Aug 2014 07:19:06 -0700 template to send logs to Lycia is ready Diffstat:
| M | src/main/resources/application.conf | | | 9 | ++++++++- |
| A | src/main/scala/inc/pyc/chimera/lycia/Logger.scala | | | 67 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf @@ -17,8 +17,15 @@ blockchain { akka { #extensions = ["kamon.statsd.StatsD", "kamon.metric.Metrics"] + loggers = ["akka.event.Logging$DefaultLogger", "inc.pyc.chimera.lycia.Logger"] loglevel = "INFO" - log-dead-letters = off + + remote { + + # do not log remote messages since we will be sending logs to Lycia + log-sent-messages = off + log-received-messages = off + } } diff --git a/src/main/scala/inc/pyc/chimera/lycia/Logger.scala b/src/main/scala/inc/pyc/chimera/lycia/Logger.scala @@ -0,0 +1,67 @@ +package inc.pyc.chimera +package lycia + +import akka.actor._ +import akka.event.Logging._ +import java.text.SimpleDateFormat +import java.util.Date + +class Logger extends Actor { + + def receive = { + case InitializeLogger(_) => sender() ! LoggerInitialized + case e: Error => error(e) + case e: Warning => warning(e) + case e: Info => info(e) + case e: Debug => debug(e) + } + + def send(msg: String): Unit = { + // TODO send log to Lycia + } + + private val date = new Date() + private val dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS") + private val errorFormat = "[ERROR] [%s] [%s] [%s] %s%s" + private val errorFormatWithoutCause = "[ERROR] [%s] [%s] [%s] %s" + private val warningFormat = "[WARN] [%s] [%s] [%s] %s" + private val infoFormat = "[INFO] [%s] [%s] [%s] %s" + private val debugFormat = "[DEBUG] [%s] [%s] [%s] %s" + + def timestamp(event: LogEvent): String = synchronized { + date.setTime(event.timestamp) + dateFormat.format(date) + } + + def error(event: Error): Unit = { + val f = if (event.cause == Error.NoCause) errorFormatWithoutCause else errorFormat + send(f.format( + timestamp(event), + event.thread.getName, + event.logSource, + event.message, + stackTraceFor(event.cause))) + } + + def warning(event: Warning): Unit = + send(warningFormat.format( + timestamp(event), + event.thread.getName, + event.logSource, + event.message)) + + def info(event: Info): Unit = + send(infoFormat.format( + timestamp(event), + event.thread.getName, + event.logSource, + event.message)) + + def debug(event: Debug): Unit = + send(debugFormat.format( + timestamp(event), + event.thread.getName, + event.logSource, + event.message)) +} +