De-flexing: don't use the MX logging facilities. They're cool and allow

filtering based on package, but we may not ever use that functionality and
it's far more useful to be able to freely include this Log class without
worrying that it will suck in some flex classes as well.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4535 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2007-02-06 20:49:20 +00:00
parent 4a630a5bb5
commit 9744d09e52
+18 -27
View File
@@ -2,14 +2,13 @@ package {
import flash.utils.getQualifiedClassName; import flash.utils.getQualifiedClassName;
import mx.logging.ILogger; //import mx.logging.ILogger;
import mx.logging.LogEventLevel; //import mx.logging.LogEventLevel;
import mx.logging.targets.TraceTarget; //import mx.logging.targets.TraceTarget;
/** /**
* A simple logging mechanism built on top of the standard mx logging * A simple logging mechanism.
* facilities.
* *
* This class need not be imported. * This class need not be imported.
* *
@@ -45,7 +44,7 @@ public class Log
{ {
// let's just use the full classname // let's just use the full classname
var path :String = getQualifiedClassName(spec).replace("::", "."); var path :String = getQualifiedClassName(spec).replace("::", ".");
return new Log(mx.logging.Log.getLogger(path)); return new Log(path);
} }
/** /**
@@ -54,7 +53,7 @@ public class Log
*/ */
public static function testing (... params) :void public static function testing (... params) :void
{ {
var log :ILogger = mx.logging.Log.getLogger("testing"); var log :Log = new Log("testing");
log.debug.apply(log, params); log.debug.apply(log, params);
} }
@@ -70,9 +69,9 @@ public class Log
/** /**
* @private * @private
*/ */
public function Log (dest :ILogger) public function Log (spec :String)
{ {
_dest = dest; _spec = spec;
} }
/** /**
@@ -80,7 +79,7 @@ public class Log
*/ */
public function debug (... messages) :void public function debug (... messages) :void
{ {
_dest.debug.apply(_dest, messages); doLog("[debug]", messages);
} }
/** /**
@@ -88,7 +87,7 @@ public class Log
*/ */
public function info (... messages) :void public function info (... messages) :void
{ {
_dest.info.apply(_dest, messages); doLog("[INFO]", messages);
} }
/** /**
@@ -96,7 +95,7 @@ public class Log
*/ */
public function warning (... messages) :void public function warning (... messages) :void
{ {
_dest.warn.apply(_dest, messages); doLog("[WARNING]", messages);
} }
/** /**
@@ -104,26 +103,18 @@ public class Log
*/ */
public function logStackTrace (error :Error) :void public function logStackTrace (error :Error) :void
{ {
_dest.warn(error.getStackTrace()); warning(error.getStackTrace());
} }
/** protected function doLog (level :String, messages :Array) :void
* Our static (class) initializer.
*/
private static function staticInit () :void
{ {
var targ :TraceTarget = new TraceTarget(); // TODO: better Date formatting?
targ.includeCategory = targ.includeDate = targ.includeLevel = messages.unshift(new Date().toLocaleTimeString(), level, _spec);
targ.includeTime = true; trace.apply(null, messages);
targ.filters = ["*"]; // TODO
targ.level = LogEventLevel.DEBUG;
mx.logging.Log.addTarget(targ);
} }
staticInit(); // call the static initializer /** Our log specification. */
protected var _spec :String;
/** Our true destination. */
protected var _dest :ILogger;
} }
} }