Flex 3 support?

4 views
Skip to first unread message

Chris

unread,
Feb 20, 2008, 9:51:15 PM2/20/08
to cimlogbook
Is LogBook known to work with a Flex 3 app? I've got it installed and
am able to get logging events from the demo app, but cannot get events
out of my app. Any ideas?

Chris

unread,
Feb 20, 2008, 10:44:20 PM2/20/08
to cimlogbook
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();
}
}
}

Chris

unread,
Feb 20, 2008, 10:48:39 PM2/20/08
to cimlogbook
So I haven't looked through the logbook code yet to find the root
cause, but I determined that if I used the "_test" channel name from
the demo it works -- any other name does not. Perhaps this value was
accidentally hard-coded somewhere?

arpit

unread,
Feb 20, 2008, 11:35:01 PM2/20/08
to cimlogbook
Chris,

I ran into the same problem a while back and the answer is that your
localConnection name must begin with an underscore (_).
From the localConnection class documentation:

Sometimes, you might want to make the file with the receiving
LocalConnection object more portable between domains. To avoid
specifying the domain name in the send() method, but to indicate that
the receiving and sending LocalConnection objects are not in the same
domain, precede the connection name with an underscore (_), in both
the connect() and send() calls.

Try using _st.

-arpit

arpit

unread,
Feb 20, 2008, 11:36:23 PM2/20/08
to cimlogbook
If that works for you, I will put an issue to warn users if
localConnection names dont use underscores.

-a
> > accidentally hard-coded somewhere?- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages