Oh hey, when I de-flexed our Log class I forgot that the flex version
had the capability to add targets (with their own module / log-level). Add back in this capability, in very simple form for now. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4584 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -7,6 +7,8 @@ import flash.utils.getQualifiedClassName;
|
||||
|
||||
//import mx.logging.targets.TraceTarget;
|
||||
|
||||
import com.threerings.util.LogTarget;
|
||||
|
||||
/**
|
||||
* A simple logging mechanism.
|
||||
*
|
||||
@@ -66,6 +68,25 @@ public class Log
|
||||
testing(new Error("dumpStack").getStackTrace());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a logging target.
|
||||
*/
|
||||
public static function addTarget (target :LogTarget) :void
|
||||
{
|
||||
_targets.push(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a logging target.
|
||||
*/
|
||||
public static function removeTarget (target :LogTarget) :void
|
||||
{
|
||||
var dex :int = _targets.indexOf(target);
|
||||
if (dex != -1) {
|
||||
_targets.splice(dex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -111,10 +132,20 @@ public class Log
|
||||
// TODO: better Date formatting?
|
||||
messages.unshift(new Date().toLocaleTimeString(), level, _spec);
|
||||
trace.apply(null, messages);
|
||||
|
||||
// possibly also dispatch to any other log targets.
|
||||
if (_targets.length > 0) {
|
||||
var asOne :String = messages.join(" ");
|
||||
for each (var target :LogTarget in _targets) {
|
||||
target.log(asOne);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Our log specification. */
|
||||
protected var _spec :String;
|
||||
|
||||
protected static var _targets :Array = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.threerings.util {
|
||||
|
||||
/**
|
||||
* A very simple Logging interface.
|
||||
* Used with the top-level class QUOTE in this package ENDQUOTE...
|
||||
* (it's actually up above 'com', so it never needs importing...)
|
||||
*/
|
||||
public interface LogTarget
|
||||
{
|
||||
/**
|
||||
* Log the specified message, which is already fully formatted.
|
||||
*/
|
||||
function log (msg :String) :void;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user