FYI, I've tried this in multiple browsers and am running Vista.
Here's the code:
package com.highwinds
{
import flash.events.Event;
import mx.logging.Log;
import mx.logging.ILogger;
import mx.logging.LogEvent;
import mx.logging.LogEventLevel;
import mx.utils.StringUtil;
import mx.controls.Alert;
import cim.fx.logging.targets.LocalConnectionTarget;
public class Logger
{
public static const LOCAL_CONNECTION_NAME : String = "st";
public static const DEFAULT_CATEGORY_NAME : String = "General";
private static var pCurrentLogEvent : LogEvent;
private static var pLoggingTarget : LocalConnectionTarget;
private static var pDefaultLogger : ILogger;
private static var pEventAlertQueue : Array = new Array();
/**
* Performs error trapping.
*/
public static function fail(error : Error, message : String =
null, ... args) : void
{
var message : String = Logger.trap(error, message, args);
Logger.showFatal(message);
}
public static function trap(error : Error, message : String =
null, ... args) : String
{
args = ArgsUtil.getArrayFromArgs(args);
// todo: use the message, and args parameters
var message : String =
Resources.getString("UnhandledExceptionOccurred");
message = StringUtil.substitute("{0}\n\n{1}", message,
error.message);
Logger.fatal(message);
return message;
}
/**
* Logs debugging information.
*/
public static function debug(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.DEBUG, false, message, args);
}
/**
* Logs general information.
*/
public static function info(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.INFO, false, message, args);
}
/**
* Logs a warning.
*/
public static function warning(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.WARN, false, message, args);
}
/**
* Logs an error.
*/
public static function error(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.ERROR, false, message, args);
}
/**
* Logs a fatal error, shows an alert dialog, and terminates the
application.
*/
public static function fatal(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.FATAL, false, message, args);
}
/**
* Logs debugging information and shows an alert dialog.
*/
public static function showDebug(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.DEBUG, true, message, args);
}
/**
* Logs general information and shows an alert dialog.
*/
public static function showInfo(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.INFO, true, message, args);
}
/**
* Logs a warning and shows an alert dialog.
*/
public static function showWarning(message : String, ... args) :
void
{
Logger.queueLogEvent(LogEventLevel.WARN, true, message, args);
}
/**
* Logs an error and shows an alert dialog.
*/
public static function showError(message : String, ... args) : void
{
Logger.queueLogEvent(LogEventLevel.ERROR, true, message, args);
}
/**
* Logs a fatal error, shows an alert dialog, and asks the user if
they want submit a bug report and/or terminate the application.
*/
public static function showFatal(message : String, ... args) : void
{
// todo: we need to prompt the user about submitting a bug report
and restarting the application
Logger.queueLogEvent(LogEventLevel.FATAL, true, message, args);
}
/**
* Queues a log event.
*/
public static function queueLogEvent(level : int, showAlert :
Boolean, message : String, args : Array = null) : void
{
if (args != null)
{
message = StringUtil.substitute(message, args);
}
if (Logger.pDefaultLogger == null)
{
Logger.pDefaultLogger =
Log.getLogger(Logger.DEFAULT_CATEGORY_NAME);
}
switch (level)
{
case LogEventLevel.DEBUG:
{
Logger.pDefaultLogger.debug(message);
break;
}
case LogEventLevel.INFO:
{
Logger.pDefaultLogger.info(message);
break;
}
case LogEventLevel.WARN:
{
Logger.pDefaultLogger.warn(message);
break;
}
case LogEventLevel.ERROR:
{
Logger.pDefaultLogger.error(message);
break;
}
case LogEventLevel.FATAL:
{
Logger.pDefaultLogger.fatal(message);
break;
}
default:
{
// todo: throw a better error
throw new Error();
}
}
if (showAlert)
{
var event : LogEvent = new LogEvent(message, level);
Logger.pEventAlertQueue.unshift(event);
Logger.showNextLogEvent();
}
}
public static function initialize() : void
{
if (Logger.pLoggingTarget == null)
{
Logger.pLoggingTarget = new
LocalConnectionTarget(Logger.LOCAL_CONNECTION_NAME);
Logger.pLoggingTarget.filters = ["*"];
Logger.pLoggingTarget.level = LogEventLevel.ALL;
Logger.pLoggingTarget.includeDate = true;
Logger.pLoggingTarget.includeTime = true;
Logger.pLoggingTarget.includeCategory = true;
Logger.pLoggingTarget.includeLevel = true;
}
}
public static function getLogLevelName(level : uint) : String
{
var resource : String;
switch (level)
{
case LogEventLevel.DEBUG : resource = "Debug" ; break;
case LogEventLevel.INFO : resource = "Info" ; break;
case LogEventLevel.WARN : resource = "Warning" ; break;
case LogEventLevel.ERROR : resource = "Error" ; break;
case LogEventLevel.FATAL : resource = "FatalError" ; break;
default:
{
// todo: throw a better error
throw new Error();
}
}
var name : String = Resources.getString(resource);
return name;
}
public static function getLogLevelIcon(level : uint, size : uint =
32) : Class
{
var resource : String = Logger.getLogLevelIconResourceName(level);
var icon : Class;
if (size == 16)
{
icon = Resources.getIcon16(resource);
}
else if (size == 32)
{
icon = Resources.getIcon32(resource);
}
else
{
// todo: throw a better error
throw new Error();
}
return icon;
}
public static function getLogLevelIconResourceName(level : uint) :
String
{
return NamedIcons.dialogInformation;
/*
var resource : String;
switch (level)
{
case LogEventLevel.DEBUG : resource = NamedIcons.dialogWarning ;
break; // add the debug icon
case LogEventLevel.INFO : resource =
NamedIcons.dialogInformation ; break;
case LogEventLevel.WARN : resource = NamedIcons.dialogWarning ;
break;
case LogEventLevel.ERROR : resource = NamedIcons.dialogError ;
break;
case LogEventLevel.FATAL : resource =
NamedIcons.dialogErrorFatal ; break;
default:
{
// todo: throw a better error
throw new Error();
}
}
return resource;
*/
}
private static function showNextLogEvent() : void
{
if (Logger.pCurrentLogEvent == null)
{
if (Logger.pEventAlertQueue.length > 0)
{
Logger.pCurrentLogEvent =
LogEvent(Logger.pEventAlertQueue.pop());
var message : String = Logger.pCurrentLogEvent.message;
var level : uint = LogEventLevel.INFO; //
Logger.pCurrentLogEvent.level;
var levelName : String = Logger.getLogLevelName(level);
var levelIcon : Class = Logger.getLogLevelIcon(level);
Alert.show(message, levelName, Alert.OK, Kernel.application,
Logger.logEventAlertClosed, levelIcon, Alert.OK);
}
}
}
private static function logEventAlertClosed(event : Event) : void
{
Logger.pCurrentLogEvent = null;
Logger.showNextLogEvent();
}
}
}