Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a report generator

Signed-off-by: Simon Bailey <simon@newtriks.com>
  • Loading branch information...
commit 5c5d56bc0cc87de51f376ee1d26abf599fb3d4e6 1 parent b5fa617
@newtriks authored
View
10 .markdown
@@ -0,0 +1,10 @@
+Super simple logging for Flex apps which can:
+
+* Store logs to an LSO.
+* Send logs to a Beaver AIR app (holla at me for this).
+* Generate a log report.
+
+Heads up to [Stray][0] skanked some tasty code bits from her [solMailBox][1] repos!
+
+0: https://github.com/Stray "Stray"
+1: https://github.com/Stray/solMailBox "solMailBox"
View
0  README
No changes.
View
BIN  bin/Beaver-v1.0.0.swc
Binary file not shown
View
BIN  bin/Beaver-v1.0.1.swc
Binary file not shown
View
2  build.properties
@@ -15,7 +15,7 @@ AUTHOR = Simon Bailey
PROJECT.OWNER = Newtriks
PROJECT.OWNER.URL = http://www.newtriks.com
PROJECT.FULLNAME = Beaver
-PROJECT.VERSION = 1.0.0
+PROJECT.VERSION = 1.0.1
PROJECT.NAME = Beaver
PROJECT.YEAR = 2012
PROJECT.URL = "http://localhost/"
View
28 src/com/newtriks/logging/core/BeaverTrunk.as
@@ -2,18 +2,20 @@
package com.newtriks.logging.core {
import com.newtriks.logging.helpers.BeaverUtil;
+import com.newtriks.logging.values.Log;
import flash.events.AsyncErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import flash.net.SharedObject;
+import flash.net.registerClassAlias;
import flash.system.Security;
import flash.utils.getQualifiedClassName;
import mx.logging.LogEventLevel;
-public class BeaverTrunk {
+public class BeaverTrunk implements IBeaverTrunk {
// Local connection
private var connection:LocalConnection = new LocalConnection();
private var lcHandler:String = "lcHandler";
@@ -34,6 +36,7 @@ public class BeaverTrunk {
this.solName = solName;
logsVector = new Vector.<Log>();
currentIndex = 1;
+ registerClassAlias("com.newtriks.logging.values.Log", Log);
}
/**
@@ -42,7 +45,7 @@ public class BeaverTrunk {
public function saveNewLog(message:String, sender:Object, level:int):void {
var qualifiedClassName:String = getQualifiedClassName(sender);
- var log:Log = new Log(nextID, message, qualifiedClassName, level, dateTimeStamp);
+ var log:Log = buildLog(message, qualifiedClassName, level);
logsVector.push(log);
saveToSol();
updateIndexing(log);
@@ -50,6 +53,7 @@ public class BeaverTrunk {
}
public function get logs():Vector.<Log> {
+ readFromSol();
return logsVector;
}
@@ -65,6 +69,16 @@ public class BeaverTrunk {
sol.close();
}
+ protected function readFromSol():void
+ {
+ var mailSol:SharedObject=getSol();
+ var solData:Object=mailSol.data;
+ if(solData.logs!=null)
+ {
+ logsVector=solData.logs;
+ }
+ }
+
private function sendToBeaver(message:String, qualifiedClassName:String, level:int = 4):void {
if (!hasEventListeners) {
connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
@@ -89,6 +103,16 @@ public class BeaverTrunk {
}
}
+ private function buildLog(message:String, qualifiedClassName:String, level:int):Log {
+ var currentLog:Log = new Log();
+ currentLog.id = nextID;
+ currentLog.body = message;
+ currentLog.sender = qualifiedClassName;
+ currentLog.level = level;
+ currentLog.dateTimeStamp = dateTimeStamp;
+ return currentLog;
+ }
+
private function updateIndexing(log:Log):void {
currentIndex = Math.max(currentIndex, log.id);
}
View
4 src/com/newtriks/logging/core/IBeaverTrunk.as
@@ -1,7 +1,9 @@
/** @author: Simon Bailey simon@newtriks.com */
package com.newtriks.logging.core {
+import com.newtriks.logging.values.Log;
+
public interface IBeaverTrunk {
- function saveNewLog(message:String, sender:String, level:int):void;
+ function saveNewLog(message:String, sender:Object, level:int):void;
function get logs():Vector.<Log>;
}
}
View
19 src/com/newtriks/logging/core/Log.as
@@ -1,19 +0,0 @@
-/** @author: Simon Bailey simon@newtriks.com */
-package com.newtriks.logging.core {
-public class Log {
-
- public var id:uint;
- public var body:String;
- public var sender:String;
- public var level:uint;
- public var dateTimeStamp:Date;
-
- public function Log(id:uint, body:String, sender:String, level:uint, dateTimeStamp:Date) {
- this.id = id;
- this.body = body;
- this.sender = sender;
- this.level = level;
- this.dateTimeStamp = dateTimeStamp;
- }
-}
-}
View
58 src/com/newtriks/logging/parsers/GenerateLogReport.as
@@ -0,0 +1,58 @@
+/** @author: Simon Bailey simon@newtriks.com */
+package com.newtriks.logging.parsers {
+
+import com.newtriks.logging.values.Log;
+
+import mx.formatters.DateFormatter;
+import mx.logging.LogEvent;
+import mx.utils.StringUtil;
+
+public class GenerateLogReport {
+ public static function getUserID(logs:Vector.<Log>):String {
+ var i:int;
+ var length:int = logs.length;
+ var currentRecord:Log;
+ var log_id:String = "";
+ var message:String = "";
+ for (i = 0; i < length; i++) {
+ currentRecord = logs[i] as Log;
+ message = currentRecord.body;
+ if (message.indexOf("log_id") >= 0) {
+ log_id = message.slice(message.lastIndexOf(":") + 1, message.length);
+ }
+ }
+ return log_id;
+ }
+
+ public static function generateReport(logs:Vector.<Log>):String {
+ var i:int;
+ var length:int = logs.length - 1;
+ var currentLog:Log;
+ var currentRecordText:String = "";
+ var logText:String = linePartition.concat("Start of Beaver log report", linePartition);
+ for (i = length; i >= 0; i--) {
+ currentLog = logs[i] as Log;
+ currentRecordText = formatCurrentRecord(currentLog);
+ logText = logText.concat(currentRecordText, linePartition);
+ }
+ logText = logText.concat("\n\nEnd of Beaver log report [generated at ".concat(format(new Date(), "H:NN:SS MM/DD/YY"), "]", linePartition));
+ return logText;
+ }
+
+ protected static function formatCurrentRecord(record:Log):String {
+ var recordText:String = StringUtil.substitute("Date: {0} >> \nLevel: {1} >> \nMessage: {2}", format(record.dateTimeStamp, "H:NN:SS MM/DD/YY"), LogEvent.getLevelString(record.level), record.body);
+ return recordText;
+ }
+
+ public static function format(obj_Date:Object, str_dateFormat:String):String {
+ var f:DateFormatter = new DateFormatter();
+ f.formatString = str_dateFormat;
+ return f.format(obj_Date);
+ }
+
+ public static function get linePartition():String
+ {
+ return "\n\n===========================\n\n";
+ }
+}
+}
View
14 src/com/newtriks/logging/values/Log.as
@@ -0,0 +1,14 @@
+/** @author: Simon Bailey simon@newtriks.com */
+package com.newtriks.logging.values {
+public class Log {
+
+ public var id:uint;
+ public var body:String;
+ public var sender:String;
+ public var level:uint;
+ public var dateTimeStamp:Date;
+
+ public function Log() {
+ }
+}
+}
View
7 src/com/newtriks/logging/values/LogReport.as
@@ -0,0 +1,7 @@
+/** @author: Simon Bailey simon@newtriks.com */
+package com.newtriks.logging.values {
+public class LogReport {
+ public var log_id:String;
+ public var report:String;
+}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.