Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a report generator

Signed-off-by: Simon Bailey <simon@newtriks.com>
  • Loading branch information...
commit 5c5d56bc0cc87de51f376ee1d26abf599fb3d4e6 1 parent b5fa617
Simon Bailey authored
10 .markdown
Source Rendered
... ... @@ -0,0 +1,10 @@
  1 +Super simple logging for Flex apps which can:
  2 +
  3 +* Store logs to an LSO.
  4 +* Send logs to a Beaver AIR app (holla at me for this).
  5 +* Generate a log report.
  6 +
  7 +Heads up to [Stray][0] skanked some tasty code bits from her [solMailBox][1] repos!
  8 +
  9 +0: https://github.com/Stray "Stray"
  10 +1: https://github.com/Stray/solMailBox "solMailBox"
0  README
No changes.
BIN  bin/Beaver-v1.0.0.swc
Binary file not shown
BIN  bin/Beaver-v1.0.1.swc
Binary file not shown
2  build.properties
@@ -15,7 +15,7 @@ AUTHOR = Simon Bailey
15 15 PROJECT.OWNER = Newtriks
16 16 PROJECT.OWNER.URL = http://www.newtriks.com
17 17 PROJECT.FULLNAME = Beaver
18   -PROJECT.VERSION = 1.0.0
  18 +PROJECT.VERSION = 1.0.1
19 19 PROJECT.NAME = Beaver
20 20 PROJECT.YEAR = 2012
21 21 PROJECT.URL = "http://localhost/"
28 src/com/newtriks/logging/core/BeaverTrunk.as
@@ -2,18 +2,20 @@
2 2 package com.newtriks.logging.core {
3 3
4 4 import com.newtriks.logging.helpers.BeaverUtil;
  5 +import com.newtriks.logging.values.Log;
5 6
6 7 import flash.events.AsyncErrorEvent;
7 8 import flash.events.SecurityErrorEvent;
8 9 import flash.events.StatusEvent;
9 10 import flash.net.LocalConnection;
10 11 import flash.net.SharedObject;
  12 +import flash.net.registerClassAlias;
11 13 import flash.system.Security;
12 14 import flash.utils.getQualifiedClassName;
13 15
14 16 import mx.logging.LogEventLevel;
15 17
16   -public class BeaverTrunk {
  18 +public class BeaverTrunk implements IBeaverTrunk {
17 19 // Local connection
18 20 private var connection:LocalConnection = new LocalConnection();
19 21 private var lcHandler:String = "lcHandler";
@@ -34,6 +36,7 @@ public class BeaverTrunk {
34 36 this.solName = solName;
35 37 logsVector = new Vector.<Log>();
36 38 currentIndex = 1;
  39 + registerClassAlias("com.newtriks.logging.values.Log", Log);
37 40 }
38 41
39 42 /**
@@ -42,7 +45,7 @@ public class BeaverTrunk {
42 45
43 46 public function saveNewLog(message:String, sender:Object, level:int):void {
44 47 var qualifiedClassName:String = getQualifiedClassName(sender);
45   - var log:Log = new Log(nextID, message, qualifiedClassName, level, dateTimeStamp);
  48 + var log:Log = buildLog(message, qualifiedClassName, level);
46 49 logsVector.push(log);
47 50 saveToSol();
48 51 updateIndexing(log);
@@ -50,6 +53,7 @@ public class BeaverTrunk {
50 53 }
51 54
52 55 public function get logs():Vector.<Log> {
  56 + readFromSol();
53 57 return logsVector;
54 58 }
55 59
@@ -65,6 +69,16 @@ public class BeaverTrunk {
65 69 sol.close();
66 70 }
67 71
  72 + protected function readFromSol():void
  73 + {
  74 + var mailSol:SharedObject=getSol();
  75 + var solData:Object=mailSol.data;
  76 + if(solData.logs!=null)
  77 + {
  78 + logsVector=solData.logs;
  79 + }
  80 + }
  81 +
68 82 private function sendToBeaver(message:String, qualifiedClassName:String, level:int = 4):void {
69 83 if (!hasEventListeners) {
70 84 connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
@@ -89,6 +103,16 @@ public class BeaverTrunk {
89 103 }
90 104 }
91 105
  106 + private function buildLog(message:String, qualifiedClassName:String, level:int):Log {
  107 + var currentLog:Log = new Log();
  108 + currentLog.id = nextID;
  109 + currentLog.body = message;
  110 + currentLog.sender = qualifiedClassName;
  111 + currentLog.level = level;
  112 + currentLog.dateTimeStamp = dateTimeStamp;
  113 + return currentLog;
  114 + }
  115 +
92 116 private function updateIndexing(log:Log):void {
93 117 currentIndex = Math.max(currentIndex, log.id);
94 118 }
4 src/com/newtriks/logging/core/IBeaverTrunk.as
... ... @@ -1,7 +1,9 @@
1 1 /** @author: Simon Bailey simon@newtriks.com */
2 2 package com.newtriks.logging.core {
  3 +import com.newtriks.logging.values.Log;
  4 +
3 5 public interface IBeaverTrunk {
4   - function saveNewLog(message:String, sender:String, level:int):void;
  6 + function saveNewLog(message:String, sender:Object, level:int):void;
5 7 function get logs():Vector.<Log>;
6 8 }
7 9 }
19 src/com/newtriks/logging/core/Log.as
... ... @@ -1,19 +0,0 @@
1   -/** @author: Simon Bailey simon@newtriks.com */
2   -package com.newtriks.logging.core {
3   -public class Log {
4   -
5   - public var id:uint;
6   - public var body:String;
7   - public var sender:String;
8   - public var level:uint;
9   - public var dateTimeStamp:Date;
10   -
11   - public function Log(id:uint, body:String, sender:String, level:uint, dateTimeStamp:Date) {
12   - this.id = id;
13   - this.body = body;
14   - this.sender = sender;
15   - this.level = level;
16   - this.dateTimeStamp = dateTimeStamp;
17   - }
18   -}
19   -}
58 src/com/newtriks/logging/parsers/GenerateLogReport.as
... ... @@ -0,0 +1,58 @@
  1 +/** @author: Simon Bailey simon@newtriks.com */
  2 +package com.newtriks.logging.parsers {
  3 +
  4 +import com.newtriks.logging.values.Log;
  5 +
  6 +import mx.formatters.DateFormatter;
  7 +import mx.logging.LogEvent;
  8 +import mx.utils.StringUtil;
  9 +
  10 +public class GenerateLogReport {
  11 + public static function getUserID(logs:Vector.<Log>):String {
  12 + var i:int;
  13 + var length:int = logs.length;
  14 + var currentRecord:Log;
  15 + var log_id:String = "";
  16 + var message:String = "";
  17 + for (i = 0; i < length; i++) {
  18 + currentRecord = logs[i] as Log;
  19 + message = currentRecord.body;
  20 + if (message.indexOf("log_id") >= 0) {
  21 + log_id = message.slice(message.lastIndexOf(":") + 1, message.length);
  22 + }
  23 + }
  24 + return log_id;
  25 + }
  26 +
  27 + public static function generateReport(logs:Vector.<Log>):String {
  28 + var i:int;
  29 + var length:int = logs.length - 1;
  30 + var currentLog:Log;
  31 + var currentRecordText:String = "";
  32 + var logText:String = linePartition.concat("Start of Beaver log report", linePartition);
  33 + for (i = length; i >= 0; i--) {
  34 + currentLog = logs[i] as Log;
  35 + currentRecordText = formatCurrentRecord(currentLog);
  36 + logText = logText.concat(currentRecordText, linePartition);
  37 + }
  38 + logText = logText.concat("\n\nEnd of Beaver log report [generated at ".concat(format(new Date(), "H:NN:SS MM/DD/YY"), "]", linePartition));
  39 + return logText;
  40 + }
  41 +
  42 + protected static function formatCurrentRecord(record:Log):String {
  43 + 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);
  44 + return recordText;
  45 + }
  46 +
  47 + public static function format(obj_Date:Object, str_dateFormat:String):String {
  48 + var f:DateFormatter = new DateFormatter();
  49 + f.formatString = str_dateFormat;
  50 + return f.format(obj_Date);
  51 + }
  52 +
  53 + public static function get linePartition():String
  54 + {
  55 + return "\n\n===========================\n\n";
  56 + }
  57 +}
  58 +}
14 src/com/newtriks/logging/values/Log.as
... ... @@ -0,0 +1,14 @@
  1 +/** @author: Simon Bailey simon@newtriks.com */
  2 +package com.newtriks.logging.values {
  3 +public class Log {
  4 +
  5 + public var id:uint;
  6 + public var body:String;
  7 + public var sender:String;
  8 + public var level:uint;
  9 + public var dateTimeStamp:Date;
  10 +
  11 + public function Log() {
  12 + }
  13 +}
  14 +}
7 src/com/newtriks/logging/values/LogReport.as
... ... @@ -0,0 +1,7 @@
  1 +/** @author: Simon Bailey simon@newtriks.com */
  2 +package com.newtriks.logging.values {
  3 +public class LogReport {
  4 + public var log_id:String;
  5 + public var report:String;
  6 +}
  7 +}

0 comments on commit 5c5d56b

Please sign in to comment.
Something went wrong with that request. Please try again.