diff --git a/src/as/Log.as b/src/as/Log.as index 4424f9f3f..e8986a794 100644 --- a/src/as/Log.as +++ b/src/as/Log.as @@ -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 = []; } } diff --git a/src/as/com/threerings/util/LogTarget.as b/src/as/com/threerings/util/LogTarget.as new file mode 100644 index 000000000..724d78910 --- /dev/null +++ b/src/as/com/threerings/util/LogTarget.as @@ -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; +} +}