SOS Logging Target

A few days ago Powerflasher released a new version of their logging tool SOS. I have used it in the past but stopped using it because I switched to Mac. Since the new version also runs on OS X I gave the new version a try and it works nicely.

I have posted a little extension for SOS about two years ago and now I made a little update which is easier to use. It works the same way as the TraceTarget I already blogged about.

The project is hosted on GitHub.
In you Flex project simply put this line into you main MXML:

And add the namespace: xmlns:logging=”com.soenkerohde.logging.*”

The rest works like described in my post about TraceTarget.
This version also supports multiline logs which can show up collapsed and can be expanded:

SOS

The application code for the example above:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
	xmlns:logging="com.soenkerohde.logging.*"
	creationComplete="init()">
 
	<mx:Script>
		<![CDATA[
			import mx.logging.Log;
			import mx.logging.ILogger;
 
			private static const logger:ILogger = Log.getLogger("Main");
 
			private function init():void
			{
				logger.debug("debug");
				logger.info("info");
				logger.warn("warn");
				logger.error("error");
				logger.fatal("fatal");
 
				logger.info("This is a multiline log example\nwith a second line.");
			}
 
		]]>
	</mx:Script>
 
	<logging:SOSLoggingTarget
		fieldSeparator="->"
		includeCategory="true"
		includeLevel="true"
		includeTime="true" />
 
</mx:Application>

30 comments to SOS Logging Target

  • Richard Jewson

    Hi,

    Nice utility, thanks. Might be worth mentioning that after you add the namespace declaration you need to add the logger with:

    ” includeCategory=”true” includeLevel=”true” includeTime=”true”/>

    I do have a problem with using this logger and when my app makes a external network access (via HTTPService for example). It seems to lose connection at that point – Any pointer?

  • Hi Richard,
    I don’t know why external call might disconncet SOS.
    Do you have a small testcase so I can try it on my own?

  • Richard Jewson

    Hi,

    I dont have a short but but it happens if:
    1) Setup basic mxml app with SOSLogger
    2) Log something to get the connection running
    3) Call HTTP Service (anything external)
    4) SOS Max then opens a dialog saying ‘Command Error’ and the text of the box is:

    The processing instruction target matching “[xX][mM][lL]” is not allowed.

  • Richard Jewson

    After some further tests I think it might just be log statements i the Flex Framework. If I filter them out the error doesn’t happen.

  • Hi Richard,
    I updated the SWC. Now “<” in log messages will be replaced with “^” so SOS has no problems with an opening tag. Please try and report if this fixes your problem.

  • Richard Jewson

    Hi,

    That fixes the problem. The XML looks a bit odd:

    ^tag>somedata^/tag>

    but it works. Thanks for the update!

  • I know. If you have a better idea let me know.
    I will release the code later this year when I have a bit more time.

  • Ronzoni

    Hey, great work. thanks. Can you also publish the source code? I tried decompiling the SWC, but it didn’t come out so well.
    I have my own logging framework that I use in AS3 projects, and I’m not using mx.logging.ILoggingTarget. I repackaged and refactored the mx log classes because they statically linked in a bunch of flex stuff.

  • Just using this for the first time. I think the fix you noted 11/08/2008 has blown CDATA handling which now breaks the connection?

    In my example I’m using HTTPService to get an RSS feed that contains CDATA, which seems to have been translated to ^![CDATA[TheDataHere]]>

    As a result resulting logging breaks SOS max with the following displayed in a “Command Error:” window:

    The character sequence “]]>” must not appear in content unless used to mark the end of a CDATA section.
    12:24:15.566->mx.rpc.http.HTTPService->Processing HTTPService response message:***Trimmed to fit into this blog comment***

  • Thanks for reporting. Can you please file an issue at the google code project: http://code.google.com/p/sosloggingtarget/

  • […] than write a log connector class from scratch, I downloaded one from Söenke Rohde . His class was almost perfect for my needs: by default, he only connects to the logging server if […]

  • […] It’s not really practical to write correct XML messages by hand. Thanks to Sönke Rodhe there is a good solution for Flex to minimize the chance of getting carpal tunnel syndrome due to extra typing hours. But it  […]

  • […] It’s not really practical to write correct XML messages by hand. Thanks to Sönke Rodhe there is a good solution for Flex to minimize the chance of getting carpal tunnel syndrome due to extra typing hours. But it  […]

  • Hey,

    I’m trying to introspect an object using the SOSLoggingTarget and am not having much luck. In fact, appending anything after the first parameter (which has to be a String) when calling log.info doesn’t trace anything to the SOS Max panel.

    For instance:

    var myObj:Object = {name: “myName”, value: “blah”};
    log.info(“some text here”, myObj);

    This results in “some text here” being echoed to the SOS panel but myObj is nowhere to be seen.

    Any clues on what I’m doing wrong? Or is this not supported in the current version of the code?

  • Jason, if you use trace the output would look like this:

    some text here [object Object]

    I currently don’t know why “[object Object]” is missing in SOS but I will look into it. Can please open an issue in the Google Code project?

    However, if you want to log/trace objects you should use a real class and implement the toString method accordingly.

  • Jason, if your using standart flex logging API, code must look like:

    var myObj:Object = {name: “myName”, value: “blah”};
    log.info(”some text here {0}”, myObj);

    test it!

  • Sönke, i’m filed the issue in google code page of project.
    i’m think – it’s real error in logic…

    let’s try it with simple string:

    “str1 \n str2 \n str3 \n str4”

    here in send () method:
    ….
    msg = StringUtil.replace(msg.substr(msg.indexOf(“\n”) + 1, msg.length),
    “<“, “^”);
    msg = msg.substr(msg.indexOf(“\n”) + 1, msg.length);
    ….

    first it removes str1 and second removes str2
    finally we have in msg only – “str3 \n str4”

    str1 – we have in title of message

    And What about str2?!We will never see it in SOS!

  • Andrew, thanks for reporting. I will look into it.
    If you would like to provide a patch I am also happy to integrate it!

  • Hello!
    I’ve made it :)
    modifed class SOSLoggingTarget to make it better and more stable in logging complex messages.
    Basic improvments are:
    1. all manipulations in send() with xml object. It’s simpler to work.
    2. remove all CDATA in message if exists (i don’t know now what about CDATA in CDATA… on this moment code excludes this situation by removing all CDATA-sections in source message)
    3. place body (and title if full) of message in one CDATA-section for all text of message. This makes text in message safe to display in SOS.

    sample project with sources attached in issue #2 on google code hosting of project in Issues section.
    or
    you can download it here http://www.dgserv.ru/dns/flash/sos/sosSample.zip

    Let me know, please, if it usable for project or if you have any errors/troubles.

  • Thanks Andrew, it is really saver to wrap all messages within CDATA tag. I’ll look into it!

  • döff

    Andrew, whats the function of the public setter/getter for _connect… if set outside, nothing happens, but it does change the _connect value… which in then is only used through getter from outside? and is kind of malfunctional, as the thing might be connected eventhough false is returned.

    What am I missing here 😀

  • döff, what’s your problem here?
    Is this something with the suggest patch from andrew?
    otherwise you can look into the source here: http://code.google.com/p/sosloggingtarget/source/browse/trunk/src/com/soenkerohde/logging/SOSLoggingTarget.as

  • döff

    I was commenting on the source of Andrew. And just didn’t figure out what the public connect setter/getter API is used for.

  • @Andrew – thanks for the tip re: log.info(”some text here {0}”, myObj);

    How on earth did you figure out that you had to put {0} within the first string parameter? There doesn’t seem to be anything that suggests you need to do this in the Flex logging API docs.

  • Jason, this is normal logging syntax.
    Try log.debug(“example {0}+{1}={2}”, 1, 1, 2);

    Will output: example 1+1=2
    The {} is a placeholder and is for instance also used in resource property file for localization.

  • döff, You’re right. I added a get method to verify the connection outside of class code. And erred in using the getter/setter code generation in fashdevelop :). Yes, only getter makes sense. Corrected.

  • I just made an update. I think there is no need to wrap with CDATA since this also shows up in SOS. Now I replace “<” in multiline logs with “<” which works fine. I did not see the problem Andrew reported that the second line does not show up.

    The new lib can be downloaded here: http://code.google.com/p/sosloggingtarget/downloads/list

  • Logging in Flex…

    ???????, ???? ??????? ????? ??????? ? ???, ????? ???????????? ?????? ?????? trace. ?????? ?? ?????? ???? ???? ????? ?????? ??????? ?????? ?????????? ? ???. ?????????? ??? logging API (…

  • Hi,

    You could check the LogMeister project I started at http://github.com/base42/LogMeister it’s a combination of a lot of loggers around (Trazzle, SosMax, Yalog, MosterDebugger)…. It’s really easy to switch and to use…

    And open source!!!