<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Stefan B.log</title>
	<atom:link href="http://blog.sbistram.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sbistram.de</link>
	<description>for whatever reason</description>
	<pubDate>Thu, 12 Feb 2009 20:13:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adobe AIR Needs to Become a Real Desktop Platform</title>
		<link>http://blog.sbistram.de/2009/02/04/adobe-air-needs-to-become-a-real-desktop-platform/</link>
		<comments>http://blog.sbistram.de/2009/02/04/adobe-air-needs-to-become-a-real-desktop-platform/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 15:50:22 +0000</pubDate>
		<dc:creator>Stefan Bistram</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.sbistram.de/?p=644</guid>
		<description><![CDATA[that&#8217;s kind of funny, getting an email from Adobe  announcing Adobe® AIR™ 1.5 for Linux® in large letters:
BREAK FREE FROM THE BROWSER
I don&#8217;t want to break free (at least not from the browser  ). I want a competitive desktop solution using Flex instead of Swing or SWT, but so far that&#8217;s not what [...]]]></description>
			<content:encoded><![CDATA[<p>that&#8217;s kind of funny, getting an email from Adobe  announcing <a href="http://www.adobe.com/products/air/">Adobe® AIR</a>™ 1.5 for Linux® in large letters:</p>
<blockquote><p>BREAK FREE FROM THE BROWSER</p></blockquote>
<p>I don&#8217;t want to break free (at least not from the browser <img src='http://blog.sbistram.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ). I want a competitive desktop solution using <code>Flex</code> instead of <code>Swing</code> or <code>SWT</code>, but so far that&#8217;s not what I can get. If you want to know what is still <strong>the problem with AIR</strong> (IMHO), look at Mike Chamber’s blog about the <a href="http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/">CommandProxy</a>.</p>
<p>I&#8217;ve used the same approach (communication via sockets) to access the <code><a href="http://www.ruby-lang.org">Ruby Runtime</a></code> and execute <code>Ruby</code> scripts on a <code>Windows XP</code> machine and do some <code>MS</code> automation (see <a href="http://rubyonwindows.blogspot.com/search/label/win32ole">Ruby On Windows</a>). But that was just a hack and in my case for a special kind of application in mind not a feasible solution.</p>
<p>I attended the <a href="http://onair.adobe.com/">Adobe on AIR Tour</a> in Amsterdam in april last year to take a fresh look on AIR and to talk to some of the Adobe guys, <a href="http://www.flickr.com/photos/diverted/2393044693/">here</a> with Mike Chambers (you can run, but you can&#8217;t hide). I tried to find out what is their point of view and what to expect from AIR in the future and what Adobe is aiming for - another widget toolkit or a real desktop platform? But unfortunately the answer was not clear. Now we are two minor AIR releases (1.1, 1.5) further ahead and it&#8217;s still not clear to me. Ok, ok, I know it&#8217;s all about security and cross platform issues, but I still think Adobe is missing the point - even Java had <a href="http://de.wikipedia.org/wiki/Java_Native_Interface">JNI</a> just from the start and SUN was adding more and more platform specific features to the JDK and has launched the JDesktop Integration Components (<a href="http://javadesktop.org/articles/jdic/">JDIC</a>) project on j<a href="http://www.javadesktop.org">avadesktop.org</a> - for good reasons.</p>
<p>I&#8217;ve seen this <a href="http://flex.sys-con.com/node/749800">article</a> written by Yakov Fain and couldn&#8217;t agree more:</p>
<blockquote><p>Dear Adobe, please make AIR a  full-fledged desktop development platform. You can’t be a little pregnant.</p></blockquote>
<p><br/>Please don&#8217;t get me wrong - I like <code>AIR</code>, especially that Adobe has integrated the <a href="http://webkit.org/">WebKit</a> browser engine (can&#8217;t wait for <a href="http://weblogs.java.net/blog/alex2d/archive/2008/12/jwebpane_projec.html">JWebPane</a>). I wish I would have the same HTML stuff in <code>Flex</code> running in a browser (but that&#8217;s another story).</p>
<p>So, Adobe, please give us the freedom to rock out on any platform! Yes, I want to break free&#8230;</p>
<p>Btw, here is Adobe&#8217;s demo AIR application to show some nice features:</p>
<p align="center"><iframe align="middle" width="215" height="180" frameborder="0" scrolling="no" src="http://tourdeflex.adobe.com/badge/"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sbistram.de/2009/02/04/adobe-air-needs-to-become-a-real-desktop-platform/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex: A MatchDataGrid Demo</title>
		<link>http://blog.sbistram.de/2009/02/02/flex-a-matchdatagrid-demo/</link>
		<comments>http://blog.sbistram.de/2009/02/02/flex-a-matchdatagrid-demo/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 21:32:18 +0000</pubDate>
		<dc:creator>Stefan Bistram</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[AS3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.sbistram.de/?p=605</guid>
		<description><![CDATA[In this post I mentioned that the rendering of a MatchDataGrid can be a bit slow when too many visible cells are used. Ok, here is a full size demo. And I&#8217;ve added some features:


Font size slider


Yahoo theme switch


Some settings stored on client side as LSO (Local Shared Object)


To be continued&#8230;



]]></description>
			<content:encoded><![CDATA[<p>In this <a href="http://blog.sbistram.de/2009/01/14/flex-enhanced-search-flex3-datagrid/">post</a> I mentioned that the rendering of a <code>MatchDataGrid</code> can be a bit slow when too many visible cells are used. Ok, here is a full size <a href="http://blog.sbistram.de/wp-content/uploads/2009/flex/GridDemo/index.html">demo</a>. And I&#8217;ve added some features:</p>
<ul>
<li>
Font size slider
</li>
<li>
<a href="http://www.yswfblog.com/blog/2007/12/13/yahoo-and-flex-feel-good-in-your-own-skin/">Yahoo theme</a> switch
</li>
<li>
Some settings stored on client side as <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=lsos_2.html">LSO</a> (Local Shared Object)
</li>
<li>
To be continued&#8230;
</li>
</ul>
<p><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sbistram.de/2009/02/02/flex-a-matchdatagrid-demo/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex: Enhanced search filtering Flex3 DataGrid</title>
		<link>http://blog.sbistram.de/2009/01/14/flex-enhanced-search-flex3-datagrid/</link>
		<comments>http://blog.sbistram.de/2009/01/14/flex-enhanced-search-flex3-datagrid/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 20:17:32 +0000</pubDate>
		<dc:creator>Stefan Bistram</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[AS3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.sbistram.de/?p=340</guid>
		<description><![CDATA[In my previous post I&#8217;ve tried to customize the ComboBox; now it&#8217;s time for the DataGrid - probably the most important GUI component for enterprise applications. If you try to understand the DataGrid and the item rendering stuff in more detail (like me) you should take a look at these cool sites:

Adobe
Flex Examples
Alex&#8217;s Flex Closet
Peter [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous <a href="http://blog.sbistram.de/2008/12/26/flex-a-combobox-with-searching-and-filtering/">post</a> I&#8217;ve tried to customize the <code>ComboBox</code>; now it&#8217;s time for the <code>DataGrid</code> - probably the most important GUI component for enterprise applications. If you try to understand the <code>DataGrid</code> and the item rendering stuff in more detail (like me) you should take a look at these cool sites:</p>
<ul>
<li><a href="http://learn.adobe.com/wiki/display/Flex/DataGrid">Adobe</a></li>
<li><a href="http://blog.flexexamples.com/">Flex Examples</a></li>
<li><a href="http://blogs.adobe.com/aharui/item_renderers/">Alex&#8217;s Flex Closet</a></li>
<li><a href="http://weblogs.macromedia.com/pent/archives/2008/03/itemrenderers_p.html">Peter Ent</a></li>
<li><a href="http://www.switchonthecode.com/tutorials">switchonthecode</a></li>
</ul>
<p>I&#8217;ve created a <code>MatchDataGrid</code> with the same kind of filtering like I have done for the <code>MatchComboBox</code> and I&#8217;ve also added some code for using links and some decorator stuff. All filtering for the <code>DataGrid</code> is done on the client side (browser or AIR), this is not about <a href="http://www.gridshore.nl/2008/03/25/creating-a-flex-3-datagrid-component-with-backend-filtering/">backend filtering</a> or <a href="http://www.iamboredsoiblog.eu/index.php/Adobe-Flex/flex-datagrid-advanced-paging-and-filtering.html">paging</a>.</p>
<h3><span style="color: #333399; font-weight:bold">Demo</span></h3>
<p></p>
<p>To get a real impression I used some real data. You don&#8217;t need the Filter - <code>Checkbox</code> to switch filtering off, but I&#8217;ve added it here to show its complete functionality. Also the layout and design of the controls could be done more nicely (e.g. using <a href="http://www.rictus.com/muchado/2006/09/14/self-labeling-text-input/">SearchBox</a>), but hey, it&#8217;s just a demo!</p>
<p><!-- embed the swf file and the alternative content --><br />
<script type="text/javascript">
var flashvars = {};
var params = {};
params.base = ".";
var attributes = {};
swfobject.embedSWF("http://blog.sbistram.de/wp-content/uploads/2008/flex/MatchDataGrid/Main.swf", "matchDataGrid", "670", "260", "9.0.0", "http://blog.sbistram.de/wp-content/swf/expressInstall.swf", flashvars, params, attributes);
</script></p>
<div id="matchDataGrid">
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
<p><!-- end swf --></p>
<p>You can get the source from <a href="http://blog.sbistram.de/wp-content/uploads/2008/flex/MatchDataGrid/srcview/index.html">here</a>, but please be careful - the component was not heavily tested and so far not used in any application.</p>
<h3><span style="color: #333399; font-weight:bold">Demo data</span></h3>
<p></p>
<p>The data for the demo grid was created from a file named <code>BK05Q406.KE1</code> downloaded from a <a href="http://www.datenaustausch.de">german website</a> for health insurance matters. The content <strong>is not valid</strong> anymore, so please don&#8217;t use it for anything else! I&#8217;ve wrote a small Ruby script to transform the <a href="http://en.wikipedia.org/wiki/EDIFACT">EDIFACT</a> format into XML.</p>
<h3><span style="color: #333399; font-weight:bold">Source</span></h3>
<p></p>
<p>If you look at the source you will see that all the code for the demo is written in two files <code>Main.mxml</code> and <code>Grid.as</code> and the code for the <code>MatchDataGrid</code>, <code>MatchDataGridItemRenderer</code> and <code>MatchFilter</code> is under the package folder <code>de.sbistram.controls</code>. Some code comment is probably missing (like always), but nevertheless most of the stuff is straight forward.</p>
<h3><span style="color: #333399; font-weight:bold">Open issues</span></h3>
<p></p>
<ul>
<li>
More or less the same like with the <code>MatchComboBox</code> - not tested in any serious application so far and missing unit tests. I&#8217;m sure there are some bugs, but maybe the code is a good starting point and someone can use it.
</li>
<li>
The filter allows also filtering of one input text per column, so the GUI demo should be extended.
</li>
<li>
I replaced the lightweight <code>DataGridItemRenderer</code> with the heavyweight <code>Label</code> renderer. So this is causing rendering performance problems for grids containing more than ca. 100 visible cells.
</li>
<li>
HTML is used to mark the matched text and also used for the anchor links, but other HTML stuff is not supported and will not work! So keep it in mind.
</li>
<li>
Would be nice if the link underlines are only visible when hovering over the link (or at least as an option).
</li>
<li>
Maybe &#8216;Match&#8217; wasn&#8217;t such a good name for the controls because it has nothing to do with matching regular expressions.
</li>
</ul>
<h3><span style="color: #333399; font-weight:bold">Flex 4</span></h3>
<p></p>
<p>I hope that Flex 4 (codename Gumbo) offers more HTML support out of the box than Flex 3 - so let&#8217;s hope and wait for <code>FxDataGrid</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sbistram.de/2009/01/14/flex-enhanced-search-flex3-datagrid/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex: Enhanced search filtering Flex3 ComboBox</title>
		<link>http://blog.sbistram.de/2008/12/26/flex-a-combobox-with-searching-and-filtering/</link>
		<comments>http://blog.sbistram.de/2008/12/26/flex-a-combobox-with-searching-and-filtering/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 19:38:10 +0000</pubDate>
		<dc:creator>Stefan Bistram</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[AS3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.sbistram.de/?p=159</guid>
		<description><![CDATA[Long time ago I&#8217;ve created a custom search ComboBox in Java Swing for an enterprise application. Exploring the Flex framework I tried to find the same kind of ComboBox component. First place to look for special components is probably the flexlib, another good resource is Flex Examples. I was not lucky, so I searched the [...]]]></description>
			<content:encoded><![CDATA[<p>Long time ago I&#8217;ve created a custom search <code>ComboBox</code> in Java Swing for an enterprise application. Exploring the Flex framework I tried to find the same kind of <code>ComboBox</code> component. First place to look for special components is probably the <a href="http://code.google.com/p/flexlib/">flexlib</a>, another good resource is <a href="http://blog.flexexamples.com/">Flex Examples</a>. I was not lucky, so I searched the Web - here&#8217;s what I found:</p>
<ul>
<li>
<a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&#038;extid=1047291">adobe.com</a>
</li>
<li>
 <a href="http://www.websector.de/blog/2008/04/30/quick-tip-avoid-issues-using-adobes-autocomplete-input-component-using-flex-3/">websector.de</a>
</li>
<li>
<a href="http://hillelcoren.com/2008/11/10/flex-autocomplete-component-a-new-take-on-an-old-standard/">hillelcoren.com</a>
</li>
<li>
<a href="http://www.defusion.org.uk/code/foxycombobox-for-flex">defusion.org.uk</a>
</li>
<li>
<a href="http://www.flex888.com/703/enhanced-search-string-combobox.html">flex888.com</a>
</li>
</ul>
<h3><span style="color: #333399; font-weight:bold">Demo</span></h3>
<p></p>
<p>Ok, a lot of cool stuff, especially the <code>Autocomplete TextInput</code> component, but not exactly what I was looking for. Anyway, I thought it&#8217;s a nice exercise to see how easy or difficult it is to customize a Flex <code>Combobox</code> (btw, in Swing it was not easy at all <img src='http://blog.sbistram.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) and this is my result so far:</p>
<p><script type="text/javascript">
var flashvars = {};
var params = {};
params.base = ".";
var attributes = {};
swfobject.embedSWF("http://blog.sbistram.de/wp-content/uploads/2008/flex/MatchComboBox/MatchComboBox.swf", "matchComboBox", "480", "250", "9.0.0", "http://blog.sbistram.de/wp-content/swf/expressInstall.swf", flashvars, params, attributes);
</script></p>
<div id="matchComboBox">
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
<p>You can get the source from <a href="http://blog.sbistram.de/wp-content/uploads/2008/flex/MatchComboBox/srcview/index.html ">here</a>, but please be careful - the component was not heavily tested and so far not used in any application.</p>
<h3><span style="color: #333399; font-weight:bold">Open issues</span></h3>
<p></p>
<ul>
<li>
Actually it&#8217;s a non-editable combobox, but it still looks like an editable combobox. I&#8217;ve tried to fix this by switching from non-editable to editable and back on the fly via an approach more or less like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;">override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> focusInHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">FocusEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        editable = <span style="color: #0033ff; font-weight: bold;">true</span>;
        <span style="color: #0033ff; font-weight: bold;">super</span>.focusInHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
override <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #339966; font-weight: bold;">function</span> focusOutHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">FocusEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        editable = <span style="color: #0033ff; font-weight: bold;">false</span>;
        <span style="color: #0033ff; font-weight: bold;">super</span>.focusOutHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But unfortunately it&#8217;s not that easy. I run into several problems and fixing one issue was causing another. Maybe it&#8217;s a better idea to change the skin dynamically, but I&#8217;m not sure if this is the way to go.
</li>
<li>
Setting the <code>prompt</code> property is not working correctly.
</li>
<li>
Start editing in the input field will open the dropdown list, but when you resize the window so the dropdown list will close the dropdown list will stay invisible (see bug <a href="http://bugs.adobe.com/jira/browse/SDK-18572">issue</a>)
</li>
</ul>
<h3><span style="color: #333399; font-weight:bold">Flex 4</span></h3>
<p></p>
<p>I&#8217;m sure there are more open issues, but maybe the code is a good starting point - or should we rather wait for <code>FxComboBox</code> in Flex 4 - Gumbo (to be continued&#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sbistram.de/2008/12/26/flex-a-combobox-with-searching-and-filtering/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex: Using the Flex3 Logging API</title>
		<link>http://blog.sbistram.de/2008/12/12/flex-using-the-flex3-logging-api/</link>
		<comments>http://blog.sbistram.de/2008/12/12/flex-using-the-flex3-logging-api/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 08:41:45 +0000</pubDate>
		<dc:creator>Stefan Bistram</dc:creator>
		
		<category><![CDATA[AS3]]></category>

		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.sbistram.de/?p=82</guid>
		<description><![CDATA[The short story

Use the Flex3 Logging API in your Flex3 code, nothing else! No trace() and flashlog.txt mess and no proprietary third parties logging framework API&#8217;s.
Define a logger:

var log:ILogger = Log.getLogger&#40;&#34;de.sbistram.logtest.Foo&#34;&#41;;

and use it:

if &#40;Log.isDebug&#40;&#41;&#41; &#123;
    log.debug&#40;&#34;Foo debugging&#34;&#41;;
&#125;

That&#8217;s it - mmh, almost&#8230;
The long story

Coming from a Java log4j and Ruby log4r background I [...]]]></description>
			<content:encoded><![CDATA[<h3><span style="color:#333399; font-weight:bold">The short story</span></h3>
<p></p>
<p>Use the <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html">Flex3 Logging API</a> in your Flex3 code, nothing else! No <code>trace()</code> and <code>flashlog.txt</code> <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19323&#038;sliceId=2">mess</a> and no proprietary third parties logging framework API&#8217;s.</p>
<p>Define a logger:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">log</span><span style="color: #000000; font-weight: bold;">:</span>ILogger = Log.getLogger<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;de.sbistram.logtest.Foo&quot;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>and use it:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Log.isDebug<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #004993;">log</span>.debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Foo debugging&quot;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>That&#8217;s it - mmh, almost&#8230;</p>
<h3><span style="color: #333399; font-weight:bold">The long story</span></h3>
<p></p>
<p>Coming from a Java <a href="http://logging.apache.org/log4j/">log4j</a> and Ruby <a href="http://log4r.sourceforge.net/">log4r</a> background I was first looking for an Actionscript3 <a href="http://code.google.com/p/log4as3/">log4AS3</a>, but it seems to be not an option. Anyway, there is a nice <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html">Flex3 Logging API</a> just in place (the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html">Java Logging API</a> was introduced in JDK 1.4, too late).</p>
<p>To see the logging output you need a logging target which is normally a console. It can be the console of the Flex Builder IDE, a <a href="http://getfirebug.com/">Firebug</a> console or some kind of a standalone console. But the most important fact is that you can inject the logging output targets via the <code>mx.logging.Log#addTarget</code> method. What this means? Hang on&#8230;</p>
<h3><span style="color: #333399; font-weight:bold">Candidates</span></h3>
<p></p>
<p>I&#8217;ve created a small sample project to explore and play around with a mixture of four different logging frameworks and targets:</p>
<ul>
<li><strong>SOSLoggingTarget</strong><a href='http://fdt.powerflasher.com/products/sosmax/'><br />
<img src="http://blog.sbistram.de/wp-content/uploads/2008/12/sos.jpg" alt="Powerflasher SOS" title="SOS" width="377" height="58" class="alignnone size-full wp-image-15" /></a> see blog of <a href='http://soenkerohde.com'>Sönke Rohde</a>
</li>
<li><strong>ThunderBoltTarget</strong><br />
<a href='http://code.google.com/p/flash-thunderbolt/wiki/ThunderBoltAS3'><img src="http://blog.sbistram.de/wp-content/uploads/2008/12/thunderbolt.png" alt="" title="Thunderbolt" width="342" height="76" class="alignnone size-full wp-image-16" /></a> see blog of <a href='http://www.websector.de/blog'>Jens Krause</a>
</li>
<li><strong>FileTarget</strong><br />
<a href='http://code.google.com/p/as3corelib/'><img src="http://blog.sbistram.de/wp-content/uploads/2008/12/filetarget.png" alt="" title="\FileTarget" width="467" height="63" class="alignnone size-full wp-image-18" /></a>
</li>
<li><strong>TraceTarget</strong><br />
<a href='http://livedocs.adobe.com/flex/3/langref/mx/logging/targets/TraceTarget.html'><img src="http://blog.sbistram.de/wp-content/uploads/2008/12/tracetarget.png" alt="" title="TraceTarget" width="258" height="72" class="alignnone size-full wp-image-17" /></a>
</li>
</ul>
<p>It is just my choice, you may want to check others like <a href="http://blog.hexagonstar.com/alcon/">Alcon</a>, but the design principles should be the same.</p>
<h3><span style="color: #333399; font-weight:bold">Sample project</span></h3>
<p></p>
<p>Before you start with your own experiments take a look at the articles of the blogs mentioned above and download and install the frameworks. It may look like a complete mess to use four different logging targets in one project, but actually its fun. You need only two additional libraries and the <code id="sb">SOSLoggingTarget.as</code> file:</p>
<p><img src="http://blog.sbistram.de/wp-content/uploads/2008/12/logging-297x365.png" alt="" title="Project tree" width="294" height="365" class="alignnone size-full wp-image-19" /></p>
<p>The <code>Logging.mxml</code> class initialize the logging via <code>Config.initLogging()</code> and create a test button. Each click on it will create a <code>Foo</code> class, which generates some logging output:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span>
    creationComplete=<span style="color: #990000;">&quot;init()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">import</span> de.sbistram.config.Config;
    <span style="color: #0033ff; font-weight: bold;">import</span> de.sbistram.logtest.Foo;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        Config.initLogging<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> testLogging<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">new</span> Foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #009900;">// show some logging       </span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Script<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Button label=<span style="color: #990000;">&quot;Test Logging&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;testLogging()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application<span style="color: #000000; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>The hole logger configuration is done in the <code>Config</code> class and all dependencies on the logging frameworks and logging targets are only used in this class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
</pre></td><td class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> de.sbistram.config <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.ILogger;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.Log;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.LogEventLevel;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.targets.TraceTarget;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> com.adobe.air.logging.FileTarget;
<span style="color: #0033ff; font-weight: bold;">import</span> com.soenkerohde.logging.SOSLoggingTarget;
<span style="color: #0033ff; font-weight: bold;">import</span> org.osflash.thunderbolt.Logger;
<span style="color: #0033ff; font-weight: bold;">import</span> org.osflash.thunderbolt.ThunderBoltTarget;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> de.sbistram.logtest.Foo;
<span style="color: #0033ff; font-weight: bold;">import</span> de.sbistram.utils.LogUtils;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Config <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #009900;">// Log file URI, see source of com.adobe.air.logging.FileTarget</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> static const DEFAULT_LOG_PATH<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;app-storage:/application.log&quot;</span>;    
&nbsp;
    <span style="color: #009900;">// the log file path for air application</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #6699cc; font-weight: bold;">var</span> logFilePath<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = DEFAULT_LOG_PATH;
&nbsp;
    <span style="color: #009900;">// switch on/off different targets</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> SOS_TARGET<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>             = <span style="color: #0033ff; font-weight: bold;">true</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> THUNDERBOLT_TARGET<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>     = <span style="color: #0033ff; font-weight: bold;">false</span>;
    <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> FILE_TARGET<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>            = <span style="color: #0033ff; font-weight: bold;">true</span>;    <span style="color: #009900;">// only AIR</span>
    <span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> TRACE_TARGET<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>           = <span style="color: #0033ff; font-weight: bold;">false</span>;
&nbsp;
    <span style="color: #3f5fbf;">/**
     * Configure logging
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> initLogging<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #6699cc; font-weight: bold;">var</span> logLevel<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = LogEventLevel.ALL;
&nbsp;
        <span style="color: #009900;">// filter for packages or classes</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">filters</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = LogUtils.getFilter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>
            Config,               <span style="color: #009900;">// add this class</span>
            <span style="color: #000000;">&#91;</span>Foo<span style="color: #000000;">&#93;</span>,                <span style="color: #009900;">// instead of: &quot;de.sbistram.logtest.*&quot;</span>
            <span style="color: #004993;">Array</span>,                <span style="color: #009900;">// any class is allowed</span>
            logLevel,             <span style="color: #009900;">// you can also use an instance</span>
            <span style="color: #990000;">&quot;de.sbistram.foo.*&quot;</span>,  <span style="color: #009900;">// you can still use strings</span>
            <span style="color: #990000;">&quot;Foo.*&quot;</span> 	          <span style="color: #009900;">// to log all internal classes of Foo</span>
            <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #009900;">// so the filter array for the above filters array would be:</span>
        <span style="color: #009900;">// [de.sbistram.config.Config,de.sbistram.logtest.*,Array,int,de.sbistram.foo.*]</span>
&nbsp;
        <span style="color: #009900;">//</span>
        <span style="color: #009900;">// ThunderBoltTarget (ThunderBoltAS3_v1.0.zip)</span>
        <span style="color: #009900;">//</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>THUNDERBOLT_TARGET<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> thunderBoltTarget<span style="color: #000000; font-weight: bold;">:</span>ThunderBoltTarget = <span style="color: #0033ff; font-weight: bold;">new</span> ThunderBoltTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
            <span style="color: #009900;">// Bug?: Windows XP - automatic detection of FireFox 3.0.4 with Flash Player 10 was not working.</span>
            <span style="color: #009900;">// @see http://www.websector.de/blog/2008/06/15/10-tips-and-tricks-using-thunderbolt-as3/</span>
            Logger.console = <span style="color: #0033ff; font-weight: bold;">false</span>;    <span style="color: #009900;">// presume we're running Firefox / Firebug</span>
            <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #009900;">// next line will throw an exception without ExternalInterface, e.g. in standalone Flash Player:</span>
                <span style="color: #009900;">// Error: Error #2067: The ExternalInterface is not available in this container...</span>
                Logger.<span style="color: #004993;">error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                Logger.console = <span style="color: #0033ff; font-weight: bold;">true</span>;    <span style="color: #009900;">// use the trace output</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #009900;">// Flex3.2: Setting the level is already adding the target to the logging.</span>
            <span style="color: #009900;">// see source code: mx.logging.AbstractTarget#level</span>
            thunderBoltTarget.<span style="color: #004993;">level</span> = logLevel;            
&nbsp;
            thunderBoltTarget.<span style="color: #004993;">filters</span> = <span style="color: #004993;">filters</span>;
            Log.addTarget<span style="color: #000000;">&#40;</span>thunderBoltTarget<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//</span>
        <span style="color: #009900;">// SOS_TARGETLoggingTarget</span>
        <span style="color: #009900;">//        </span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>SOS_TARGET<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> sosTarget<span style="color: #000000; font-weight: bold;">:</span>SOSLoggingTarget = <span style="color: #0033ff; font-weight: bold;">new</span> SOSLoggingTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            sosTarget.<span style="color: #004993;">level</span> = logLevel;    
            sosTarget.fieldSeparator = <span style="color: #990000;">&quot;:&quot;</span>;
            sosTarget.includeCategory = <span style="color: #0033ff; font-weight: bold;">true</span>;
            sosTarget.includeLevel = <span style="color: #0033ff; font-weight: bold;">true</span>;
            <span style="color: #009900;">//sosTarget.filters = LogUtils.getFilter([Array]);    // only Array logging for SOS_TARGET</span>
            sosTarget.<span style="color: #004993;">filters</span> = <span style="color: #004993;">filters</span>;
&nbsp;
            Log.addTarget<span style="color: #000000;">&#40;</span>sosTarget<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">//</span>
        <span style="color: #009900;">// FileTarget (only for AIR)</span>
        <span style="color: #009900;">// Part of http://code.google.com/p/as3corelib</span>
        <span style="color: #009900;">//</span>
&nbsp;
        <span style="color: #009900;">// use conditional compilation for AIR code</span>
        <span style="color: #009900;">// @see http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html</span>
        <span style="color: #009900;">// Otherwise (un)comment this AIR part</span>
        <span style="color: #009900;">//CONFIG::air {    // conditional compilation for AIR</span>
        <span style="color: #3f5fbf;">/*
            if (FILE_TARGET) {
                import flash.filesystem.File;
                var file:File = new File(DEFAULT_LOG_PATH);
                var fileTarget:FileTarget = new FileTarget(file);
                fileTarget.fieldSeparator = &quot;:&quot;;
                fileTarget.filters = filters;
                fileTarget.includeCategory = true;
                fileTarget.includeLevel = true;
                fileTarget.includeTime = true;
                fileTarget.includeDate = true;
                Log.addTarget(fileTarget);
            }
        */</span>
        <span style="color: #009900;">//}    // end CONFIG::air</span>
&nbsp;
        <span style="color: #009900;">//</span>
        <span style="color: #009900;">// TraceTarget (redirect logging output to trace())</span>
        <span style="color: #009900;">// Enable this target in Adobe Flex Builder to see logging output in the console</span>
        <span style="color: #009900;">// The application must run in debug mode!</span>
        <span style="color: #009900;">//</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>TRACE_TARGET<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> traceTarget<span style="color: #000000; font-weight: bold;">:</span>TraceTarget = <span style="color: #0033ff; font-weight: bold;">new</span> TraceTarget<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
            traceTarget.fieldSeparator = <span style="color: #990000;">&quot;:&quot;</span>;
            traceTarget.<span style="color: #004993;">filters</span> = <span style="color: #004993;">filters</span>;
            traceTarget.includeCategory = <span style="color: #0033ff; font-weight: bold;">true</span>;
            traceTarget.includeLevel = <span style="color: #0033ff; font-weight: bold;">true</span>;
            traceTarget.includeTime = <span style="color: #0033ff; font-weight: bold;">true</span>;
            traceTarget.<span style="color: #004993;">level</span> = logLevel;
            Log.addTarget<span style="color: #000000;">&#40;</span>traceTarget<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #009900;">// start logging</span>
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Log.isDebug<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">log</span><span style="color: #000000; font-weight: bold;">:</span>ILogger = LogUtils.getLogger<span style="color: #000000;">&#40;</span>Config<span style="color: #000000;">&#41;</span>;
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>THUNDERBOLT_TARGET == <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">log</span>.debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging - ThunderBoltTarget initialized, filters: [{0}]&quot;</span>, thunderBoltTarget.<span style="color: #004993;">filters</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>SOS_TARGET<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">log</span>.debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging - SOS_TARGETLoggingTarget initialized, filters: [{0}]&quot;</span>, sosTarget.<span style="color: #004993;">filters</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #009900;">//CONFIG::air {</span>
            <span style="color: #3f5fbf;">/*
                if (FILE_TARGET) {
                    log.debug(&quot;Logging - AIR FileTarget initialized, filters: [{0}]&quot;, fileTarget.filters);
                    // Note: Under Windows XP - the dir is hidden (use 'dir /A:H')! 
                    log.debug(&quot;Logging - AIR file path: &quot; + file.nativePath);
                }
            */</span>
            <span style="color: #009900;">//} // end CONFIG:air</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>TRACE_TARGET<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">log</span>.debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging - TraceTarget initialized, filters: [{0}]&quot;</span>, traceTarget.<span style="color: #004993;">filters</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span>        
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>        
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Play around with the settings (switch targets on/off, set filters, &#8230;) and see where the logging output goes. I like to use the <a href="http://solutions.powerflasher.com/products/sosmax/">SOS console</a> for WEB- and <a href="http://www.adobe.com/products/air/">Adobe AIR</a> development. SOS is using a simple socket connection to the SOS console and is really lightweight. Thunderbolt is great for working with Firefox and the Firebug console and it has also a <a href="http://code.google.com/p/flash-thunderbolt/wiki/ThunderBoltAS3Console">Thunderbolt AIR console</a>. The <code>FileTarget</code> writes the logging statements to a file and therefore can only be used for AIR. It is missing some features (like log4j&#8217;s <code><a href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html">DailyRollingFileAppender</a></code>) and not ready for the enterprise, but a good starting point. The <code>TraceTarget</code> can be used in Flex Builder 3 to see some logging output in the console, but because it is using the <code>trace()</code> method you have to run your application in debug mode. You can also do any kind of combination of these logging targets - just try it out and see what is working for you and what you like. <img src='http://blog.sbistram.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The actual usage of the Logging API looks like e.g.:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> de.sbistram.logtest <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.ILogger;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.Log;
<span style="color: #0033ff; font-weight: bold;">import</span> de.sbistram.utils.LogUtils;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Foo <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">log</span><span style="color: #000000; font-weight: bold;">:</span>ILogger = LogUtils.getLogger<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Foo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        testLogging<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> testLogging<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #004993;">log</span>.debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging test for DEBUG&quot;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">log</span>.<span style="color: #004993;">info</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging test for INFO&quot;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">log</span>.warn<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging test for WARN&quot;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">log</span>.<span style="color: #004993;">error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging test for ERROR&quot;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #004993;">log</span>.fatal<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging test for FATAL&quot;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #6699cc; font-weight: bold;">var</span> seasons<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;spring&quot;</span>, <span style="color: #990000;">&quot;summer&quot;</span>, <span style="color: #990000;">&quot;autumn&quot;</span>, <span style="color: #990000;">&quot;winter&quot;</span><span style="color: #000000;">&#93;</span>;
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>Log.isDebug<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #009900;">// Note: Using the 'seasons' category, not Foo</span>
            LogUtils.getLogger<span style="color: #000000;">&#40;</span>seasons<span style="color: #000000;">&#41;</span>.debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;seasons = {0}&quot;</span>, seasons<span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">new</span> InternalFoo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;    <span style="color: #009900;">// check also the logger output of an internal class</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900;">//</span>
<span style="color: #009900;">// Test the logging of an internal class. Output will look like:</span>
<span style="color: #009900;">// 21:26:58.505:[DEBUG]:Foo.as.0.InternalFoo:InternalFoo logging</span>
<span style="color: #009900;">//</span>
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.ILogger;
<span style="color: #0033ff; font-weight: bold;">import</span> de.sbistram.utils.LogUtils;
&nbsp;
<span style="color: #9900cc; font-weight: bold;">class</span> InternalFoo <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">log</span><span style="color: #000000; font-weight: bold;">:</span>ILogger = LogUtils.getLogger<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> InternalFoo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">log</span>.debug<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;InternalFoo logging&quot;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The important fact here is that the code has <strong>no dependency</strong> on any third party logging stuff! It only uses the Flex3 Logging API and a helper method of the <code>LogUtils</code> class. </p>
<h3><span style="color: #333399; font-weight:bold">Best practice</span></h3>
<p></p>
<p>It is a simple case of the <a href="http://en.wikipedia.org/wiki/Dependency_injection">DI</a> design principle - Dependency Injection: The Flex3 Logging API allows you to create your own instance of a <code>ILoggingTarget</code> and inject it via the method <code>mx.logging.Log.addTarget(target:ILoggingTarget)</code>.</p>
<p>So don&#8217;t use example code like this, e.g. Thunderbolt:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> org.osflash.thunderbolt.Logger;
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> myNumber<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">5</span>;
<span style="color: #6699cc; font-weight: bold;">var</span> myString<span style="color: #000000; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Lorem ipsum&quot;</span>;
Logger.<span style="color: #004993;">error</span> <span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Logging two objects: A number typed as int and a string&quot;</span>, myNumber, myString<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>and don&#8217;t use additional features of a Logging API, e.g. Thunderbolt:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;">Logger.<span style="color: #004993;">info</span><span style="color: #000000;">&#40;</span>Logger.memorySnapshot<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// stop logging</span>
Logger.<span style="color: #004993;">hide</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
<span style="color: #009900;">// resume logging</span>
Logger.<span style="color: #004993;">hide</span> = <span style="color: #0033ff; font-weight: bold;">false</span>;
&nbsp;
Logger.about<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Again your code depends on one special Logging Framework - bad design!<br />
But as long as you stick to the Flex Logging API your code could be used across multiple projects without any changes. And the second issue - a logger should care about logging, not memory snapshots, that&#8217;s another important design principle: <a href="http://en.wikipedia.org/wiki/Separation_of_concerns">SoC</a> - Separation of Concerns.</p>
<p>Ok, and the last design principle for this article: <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> - Don&#8217;t Repeat Yourself:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> de.sbistram.logtest <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.ILogger;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.Log;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Foo <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">log</span><span style="color: #000000; font-weight: bold;">:</span>ILogger = Log.getLogger<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;de.sbistram.logtest.Foo&quot;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>What&#8217;s wrong with the code? It&#8217;s a common naming convention to use the full qualified class name for the logger category. Ok, but the information (package + class) is already there - remember: Don&#8217;t Repeat Yourself (actually I did it right now <img src='http://blog.sbistram.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ).<br />
The <code>Log.getLogger("de.sbistram.logtest.Foo")</code> should be replaced by <code>LogUtils.getLogger(this)</code> and this is just a shortcut for <code>Log.getLogger(getQualifiedClassName(this).replace("::", "."))</code>. Another advantage of not using a String is code refactoring. If the package name or the class name is changing you don&#8217;t have to update any hardcoded String references. Btw, the same principle is used in defining a filter for a logger target in the <code>LogUtils.getFilter</code> method.</p>
<p>Here&#8217;s the code of the <code>LogUtils</code> class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
</pre></td><td class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> de.sbistram.utils <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span>.<span style="color: #000000; font-weight: bold;">*</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.ILogger;
<span style="color: #0033ff; font-weight: bold;">import</span> mx.logging.Log;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LogUtils <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #009900;">//--------------------------------------------</span>
    <span style="color: #009900;">// Flex API logging support</span>
    <span style="color: #009900;">//--------------------------------------------</span>
&nbsp;
    <span style="color: #3f5fbf;">/**
     * Get an instance of an &lt;code&gt;ILogger&lt;/code&gt;
     * Use the full qualified class name as the category
     * 
     * @param    value can be a class or an instance
     * @return    mx.logging.ILogger
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getLogger<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:*</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span>ILogger <span style="color: #000000;">&#123;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> Log.getLogger<span style="color: #000000;">&#40;</span>getCategory<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #3f5fbf;">/**
     * Using the full qualified class name as the category
     * name for the logger.
     * 
     * &lt;p&gt;
     * Unfortunately the method getQualifiedClassName is 
     * returning e.g. de.sbistram.Utils::LogUtils for this class, 
     * but Log.getLogger doesn't allow ':' chars in the category
     * name, so &quot;::&quot; will be replaced by &quot;.&quot;
     *
     * Internal classes don't include the package, e.g.:
     * Foo.as$0::InternalFoo
     * &lt;/p&gt;
     * 
     * @param    value of an instance object or class
     * @return    the full qualified class name without &quot;::&quot;
     * @see http://livedocs.adobe.com/flex/3/langref/mx/logging/Log.html#getLogger()
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getCategory<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:*</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> qcn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">getQualifiedClassName</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span>;
        qcn = qcn.<span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;$&quot;</span>, <span style="color: #990000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span>;    <span style="color: #009900;">// maybe an internal class using '$'</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> qcn.<span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;::&quot;</span>, <span style="color: #990000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span>;  <span style="color: #009900;">// public class in a package using '::'</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #3f5fbf;">/**
     * Convert an array of classes or instances to an array of valid 
     * category names. 
     * 
     * - [...] means to include the complete package of the class
     *  - String filter items left untouched
     *  - For internal classes of a public class Foo -&gt; &quot;Foo.*&quot;
     * 
     * @param    values
     * @return    array of String categories
&nbsp;
     */</span>
    <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getFilter<span style="color: #000000;">&#40;</span>values<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> categories<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>;
        <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">value</span><span style="color: #000000; font-weight: bold;">:*</span> <span style="color: #0033ff; font-weight: bold;">in</span> values<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #004993;">value</span> = values<span style="color: #000000;">&#91;</span><span style="color: #004993;">value</span><span style="color: #000000;">&#93;</span>;
            <span style="color: #009900;">// [] indicate to include all classes of a package</span>
            <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> qcn<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">getQualifiedClassName</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000;">&#91;</span>0<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
                <span style="color: #004993;">value</span> = qcn.<span style="color: #004993;">slice</span><span style="color: #000000;">&#40;</span>0, qcn.<span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;::&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #004993;">concat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.*&quot;</span><span style="color: #000000;">&#41;</span>;
            <span style="color: #000000;">&#125;</span> 
            categories.<span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span> <span style="color: #0033ff; font-weight: bold;">is</span> <span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">?</span> <span style="color: #004993;">value</span> <span style="color: #000000; font-weight: bold;">:</span> getCategory<span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0033ff; font-weight: bold;">return</span> categories;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3><span style="color: #333399; font-weight:bold">Conclusion</span></h3>
<p></p>
<p>So no matter what kind of application framework you&#8217;re using (<a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm">Cairngorm</a>, <a href="http://puremvc.org/">PureMVC</a>, <a href="http://code.google.com/p/swizframework/">Swiz</a>, <a href="http://mate.asfusion.com/">Mate</a> or whatever or none at all) and no matter whether you&#8217;re just hacking a few lines of code or building the next great enterprise RIA or AIR application  - use the Flex Logging API.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sbistram.de/2008/12/12/flex-using-the-flex3-logging-api/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
