iota-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonyfaust...@apache.org
Subject [4/8] incubator-iota git commit: Saving monitoring log to separated file
Date Mon, 11 Jul 2016 18:50:34 GMT
Saving monitoring log to separated file

- Saving to same location but to file monitor_events.log


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/98976691
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/98976691
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/98976691

Branch: refs/heads/master
Commit: 98976691b7bec3a6af793bd7443ba17e011050b6
Parents: 3743740
Author: Barbara Gomes <barbaramaltagomes@gmail.com>
Authored: Fri Jul 8 16:08:36 2016 -0700
Committer: Barbara Gomes <barbaramaltagomes@gmail.com>
Committed: Mon Jul 11 10:51:42 2016 -0700

----------------------------------------------------------------------
 fey-core/src/main/resources/logback.xml         | 94 ++++++--------------
 .../scala/org/apache/iota/fey/Monitor.scala     | 29 ++++--
 2 files changed, 52 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/98976691/fey-core/src/main/resources/logback.xml
----------------------------------------------------------------------
diff --git a/fey-core/src/main/resources/logback.xml b/fey-core/src/main/resources/logback.xml
index bace975..396832f 100644
--- a/fey-core/src/main/resources/logback.xml
+++ b/fey-core/src/main/resources/logback.xml
@@ -18,83 +18,47 @@
 
 <configuration>
 
+    <property name="LOG_HOME" value="${HOME}/.fey/logs" />
+
     <appender name="FEY-CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
         <target>System.out</target>
         <encoder>
             <charset>UTF-8</charset>
-            <pattern>[%p] [%d{yy/MM/dd HH:mm:ss}] %c [%X{akkaSource}]: %msg%n</pattern>
+            <pattern>[%p] [%d{yy/MM/dd HH:mm:ss}] %c [%X{akkaSource}] : %msg%n</pattern>
         </encoder>
     </appender>
 
-    <!-- Fey core -->
-    <appender name="FEY-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <append>true</append>
-        <file>${HOME}/.fey/logs/fey_core.log</file>
-        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-            <!-- daily rollover. Make sure the path matches the one in the file element
or else
-             the rollover logs are placed in the working directory. -->
-            <fileNamePattern>${HOME}/.fey/logs/fey_core-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
-            <maxFileSize>1MB</maxFileSize>
-            <maxHistory>30</maxHistory>
-            <totalSizeCap>1GB</totalSizeCap>
-        </rollingPolicy>
+    <appender name="FEY-FILE" class="ch.qos.logback.classic.sift.SiftingAppender">
 
-       <!-- <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
-            <evaluator>
-                <expression>
-                    if(logger.startsWith("com.apache.iota.fey.FeyCore"))
-                        return true;
-                    return false;
-                </expression>
-            </evaluator>
-            <OnMismatch>DENY</OnMismatch>
-            <OnMatch>NEUTRAL</OnMatch>
-        </filter> -->
+        <!-- MDC value -->
+        <discriminator>
+            <key>fileName</key>
+            <defaultValue>fey_core</defaultValue>
+        </discriminator>
 
-        <encoder>
-            <charset>UTF-8</charset>
-            <pattern>[%p] [%d{yy/MM/dd HH:mm:ss}] %c [%X{akkaSource}]: %msg%n</pattern>
-        </encoder>
-    </appender>
+        <sift>
+            <!-- Fey core -->
+            <appender name="FEY-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+                <append>true</append>
+                <file>${LOG_HOME}/${fileName}.log</file>
+                <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+                    <!-- daily rollover. Make sure the path matches the one in the file
element or else
+                     the rollover logs are placed in the working directory. -->
+                    <fileNamePattern>${LOG_HOME}/${fileName}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+                    <maxFileSize>1MB</maxFileSize>
+                    <maxHistory>30</maxHistory>
+                    <totalSizeCap>1GB</totalSizeCap>
+                </rollingPolicy>
 
-    <!-- Orchestrations core -->
-    <!-- <appender name="FILE-ORHC" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <append>true</append>
-        <file>logs/fey_orchestrations.log</file>
-        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-            <fileNamePattern>logs/fey_orchestrations-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
-            <maxFileSize>100KB</maxFileSize>
-            <maxHistory>60</maxHistory>
-            <totalSizeCap>1GB</totalSizeCap>
-        </rollingPolicy>
+                <encoder>
+                    <charset>UTF-8</charset>
+                    <pattern>[%p] [%d{yy/MM/dd HH:mm:ss}] %c [%X{akkaSource}] : %msg%n</pattern>
+                </encoder>
+            </appender>
 
-        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
-            <evaluator>
-                <expression>
-                    if(logger.startsWith("com.apache.iota.fey.Orchestration"))
-                    return true;
-                    return false;
-                </expression>
-            </evaluator>
-            <OnMismatch>DENY</OnMismatch>
-            <OnMatch>NEUTRAL</OnMatch>
-        </filter>
+        </sift>
 
-        <encoder>
-            <charset>UTF-8</charset>
-            <pattern>[%p] [%d{yy/MM/dd HH:mm:ss}] [%X{akkaSource}]: %msg%n</pattern>
-        </encoder>
-    </appender> -->
-
-    <!-- Logging asynchronously -->
-    <!-- <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
-        <queueSize>1000</queueSize>
-        <appender-ref ref="FILE" />
-    </appender> -->
-
-    <!--
-    <logger name="com.apache.iota.fey" level="INFO" appender="FILE-FEY-CORE"/>
-    <logger name="com.apache.iota.fey.Orchestration" level="INFO" appender="FILE-ORHC"/>
-->
+    </appender>
 
     <root level="INFO">
         <appender-ref ref="FEY-FILE"/>

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/98976691/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala b/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
index 619d97c..3cff0fb 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Monitor.scala
@@ -17,35 +17,52 @@
 
 package org.apache.iota.fey
 
-import akka.actor.{Actor, ActorLogging}
+import akka.actor.Actor
+import akka.event.{DiagnosticLoggingAdapter, Logging}
 
 /**
   * Created by barbaragomes on 7/8/16.
   */
-protected class Monitor extends Actor with ActorLogging{
+protected class Monitor extends Actor {
 
   import Monitor._
 
+  val log: DiagnosticLoggingAdapter = Logging(this)
+  log.mdc(Map("fileName" -> "monitor_events"))
+
+  override def postStop() = {
+    log.clearMDC()
+  }
+
+
   override def receive: Receive = {
 
     case START(timestamp, info) =>
-      //TODO: Log
+      logInfo(sender().path.toString, EVENTS.START, timestamp, info)
       events.append(sender().path.toString,MonitorEvent(EVENTS.START, timestamp, info))
 
     case STOP(timestamp, info) =>
-    //TODO: Log
+      logInfo(sender().path.toString, EVENTS.STOP, timestamp, info)
       events.append(sender().path.toString,MonitorEvent(EVENTS.STOP, timestamp, info))
 
     case RESTART(reason, timestamp) =>
-    //TODO: Log
+      logInfo(sender().path.toString, EVENTS.RESTART, timestamp, "", reason)
       events.append(sender().path.toString,MonitorEvent(EVENTS.RESTART, timestamp, reason.getMessage))
 
     case TERMINATE(actorPath, timestamp, info) =>
-    //TODO: Log
+      logInfo(sender().path.toString, EVENTS.TERMINATE, timestamp, info)
       events.append(actorPath,MonitorEvent(EVENTS.TERMINATE, timestamp, info))
 
   }
 
+  def logInfo(path:String, event:String, timestamp: Long, info:String, reason:Throwable =
null) = {
+    if(reason != null){
+      log.error(reason, s"$event | $timestamp | $path | $info")
+    }else{
+      log.info(s"$event | $timestamp | $path | $info")
+    }
+  }
+
 }
 
 protected object Monitor{


Mime
View raw message