<?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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BEKK Open &#187; Ole Christian Langfjæran</title>
	<atom:link href="http://open.bekk.no/author/oleclangfjaran/feed/" rel="self" type="application/rss+xml" />
	<link>http://open.bekk.no</link>
	<description>Et innblikk i hva som skjer i BEKK</description>
	<lastBuildDate>Fri, 10 Sep 2010 16:43:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rent og pent med LTW</title>
		<link>http://open.bekk.no/2009/11/24/rent-og-pent-med-ltw/</link>
		<comments>http://open.bekk.no/2009/11/24/rent-og-pent-med-ltw/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 05:25:15 +0000</pubDate>
		<dc:creator>Ole Christian Langfjæran</dc:creator>
				<category><![CDATA[BEKK]]></category>
		<category><![CDATA[Teknologi]]></category>
		<category><![CDATA[domain-driven-design]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[load-time-weaving]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://open.bekk.no/?p=1495</guid>
		<description><![CDATA[Jeg liker ren og pen kode akkurat like mye som hvilken som helst annen programmerer. Det kommer litt ekstra hjertebank av å se kode smellt sammen med minimal bruk av kodelinjer og like lettleselig som siste nummer av Donald Duck. Kodesnutter du bare kan trykke Ctrl+Print og levere rett til domeneeksperten og si &#8220;var det [...]]]></description>
			<content:encoded><![CDATA[<p>Jeg liker ren og pen kode akkurat like mye som hvilken som helst annen programmerer. Det kommer litt ekstra hjertebank av å se kode smellt sammen med minimal bruk av kodelinjer og like lettleselig som siste nummer av Donald Duck. Kodesnutter du bare kan trykke Ctrl+Print og levere rett til domeneeksperten og si &#8220;var det dette du hadde i tankene?&#8221;. Kildekode som hvem-som-helst kan komme når-som-helst og refaktorere hur-fort-som-helst. Jeg liker sånt:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> InternettFasade<span style="color: #009900;">&#123;</span>
...
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> leverAnmeldelse<span style="color: #009900;">&#40;</span>Anmeldelse anmeldelse<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> anmeldelse.<span style="color: #006633;">sendFaxTilAnsvarligPolitiDistrikt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                     .<span style="color: #006633;">sendEpostTilPolitiDistrikt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                     .<span style="color: #006633;">sendBekreftelseEpostTilAnmelder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                     .<span style="color: #006633;">lagre</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                     .<span style="color: #006633;">referanseNummer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Sterkt preget av min egen lille forståelse av <a href="http://en.wikipedia.org/wiki/Domain_driven_design">Domain Driven Design </a>så passer sånn type kode meg ypperlig. Noen vil sikkert arrestere meg og si at i DDD så er det ikke opp til entitetene selv å drive å lagre, men jeg liker nå det engang sånn. Skader det så mye også egentlig? Sikkert masse annet jeg har bommet på med DDD også. Når jeg først har slike fine entiteter/modeller så synes jeg det er storveis å bare sende de rundt omkring hos forskjellige fasader og servicer helt uten å tenke meg om de har injisert de riktige repositories/servicer/validatorer osv, osv. </p>
<p>Til å begynne med gjorde jeg injiseringen i forskjellige factories som populerte entitetene med det nødvendige. Etterhvert bli disse factories&#8217;ene ganske kompliserte. Selv fikk jeg i alle fall lyst til å ordne det slik at det var bare disse factories&#8217;ene som fikk lov til å opprette domenemodellene. Da først snakker vi om skikkelig kontroll. None shall pass og one factory to rule them all. Og straks har jeg litt ekstra uønsket kompleksitet og kode. Huff. Derfor ble jeg ganske interessert i å finne ut hva denne <a href="http://static.springsource.org/spring/docs/2.5.x/reference/aop.html#aop-aj-ltw">Spring load-time-weaving</a> var for noe. Og kunne det gjøre akkurat det samme som en factory? Bare behind the scenes? Joda. Såklart. Hvorfor hadde jeg ellers giddet å skrive denne bloggen? Here&#8217;s how!</p>
<h2>Hva?</h2>
<p>Load-time-weaving er i korttekst runtime instrumentering av klassene dine. Det er slik fancy <a href="http://en.wikipedia.org/wiki/Aspect_oriented_programming">AOP</a> som legger seg rundt objektene dine og slår inn straks noen prøver seg. Prøver seg i dette tilfelle med Spring-ltw er rett etter du har opprettet et AOP-instrumentert objekt. Jeg kan illustrere med et kodeeksempel</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Configurable
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Ansatt<span style="color: #009900;">&#123;</span>
    @Autowired
    <span style="color: #000000; font-weight: bold;">private</span> AnsattRepository repo<span style="color: #339933;">;</span>
    @Autowired
    <span style="color: #000000; font-weight: bold;">private</span> EpostService epostService<span style="color: #339933;">;</span>
    ...
    <span style="color: #000000; font-weight: bold;">public</span> Ansatt lagre<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        repo.<span style="color: #006633;">lagre</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Her har vi først fortalt at klassen skal instrumenteres runtime av Spring vha annoteringen <a href="http://static.springsource.org/spring/docs/2.5.6/api/org/springframework/beans/factory/annotation/Configurable.html">@Configurable</a>. Det som skjer nå er at hver gang, og hvor som helst i koden, det kjøres en <strong>new Ansatt()</strong> så vil Spring hoppe inn og injisere EpostService og AnsattRepository fra konteksten sin. Det gjelder ikke bare koden du skriver, men også knæshe xml-to-java bibliotek og lignende. Så nå blir det fullt ut mulig å gjøre for eksempel dette:<br />
 <strong>new Ansatt(ansattNr).giSparken().sendSluttPakkePaaEpost().lagre();</strong></p>
<h2>Hvordan?</h2>
<p>Hvordan er like enkelt som å skrive new Person(). Vel.. Nesten da. Kors på halsen. Det første du må gjøre er å bruke Spring. Hvis du har slengt på @Configurable så mangler du en slik en i Spring contexten din:
</pre>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:load-time-weaver</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Da begynner Spring straks å mase om at den mangler en java-agent. Det er et annet ord for instrumenteringen som er det siste du må fikse. Det kan du gjør på forskjellige måter:</p>
<h3>Java argument</h3>
<p>For de fleste tilfeller må man sende inn java agenten som et java-argument. For eksempel for å starte den superenkle og populære Jetty sender du inn Spring sin java-agent gjennom Maven  slik(Linux):</p>
<p><strong>export MAVEN_OPTS="-javaagent:$HOME/.m2/repository/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar"</strong></p>
<p>Og da er det bare å mvn jetty:run</p>
<h3>Tomcat, GlassFish, Oracle OC4J, WebLogic</h3>
<p><div id="attachment_1761" class="wp-caption alignright" style="width: 140px"><img src="http://open.bekk.no/wp-content/uploads/2009/11/tomcat.gif" alt="Apache Tomcat" title="Apache Tomcat" width="130" height="92" class="size-full wp-image-1761" /><p class="wp-caption-text">Apache Tomcat</p></div>Med disse webserverne er det litt enklere da de har laget egne klasser for LoadTimeWeaving. For eksempel for Tomcat bruker du <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/instrument/classloading/tomcat/TomcatInstrumentableClassLoader.html">TomcatInstrumentableClassLoader</a>. Den slår du på per web-app med å legge til dette i META-INF/context.xml:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Loader</span> <span style="color: #000066;">loaderClass</span>=<span style="color: #ff0000;">&quot;org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>For at dette skal fungere så må Tomcat innstallasjonen kjenne til klassen TomcatInstrumentableClassLoader. Dvs du slenger<br />
spring-tomcat-weaver.jar i lib katalogen til Tomcat, og vips - tilgjengelig java-agent! DET burde ikke være vanskelig å overbevise drift om å tillate!</p>
<h2>Testing</h2>
<h3>Eclipse</h3>
<p>Skal du teste at load-time-weaving koden din faktisk injiserer objektene som du håper må du også her tilby en java agent. Det gjør du ved å redigere vm argumentene til den testen eller koden du skal kjøre. Dette finner du under <strong>Run=>Run Configurations=>Arguments</strong><br />
Der mangler det en slik:<br />
<strong>-javaagent:"${USER_HOME}/.m2/repository/org/springframework/spring-agent/2.5.6/spring-agent-2.5.6.jar</strong></p>
<h3>Maven</h3>
<p>Ønsker du å kjøre enhets- eller integrasjonstester som bruker load-time-weaving så redigerer du argumentene for surefire-plugin slik at den instrumenterer likt Eclipse. Det kan du gjøre slik:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-surefire-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;forkMode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>once<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/forkMode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;argLine<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			-javaagent:${settings.localRepository}/org/springframework/spring-agent/${spring.version}/spring-agent-${spring.version}.jar
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/argLine<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;useSystemClassloader<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/useSystemClassloader<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h2>Alt vel i paradis?</h2>
<p>Veeel... Det koster litt. Skal du opprette en drøss med objekter så går det atskillig raskere å gjøre det på gamlemåten med en Factory. En helt enkel test jeg gjorde viste at med en Factory fikk jeg laget 200 objekter på samme tid som det tok å lage ett @Configurable objekt. Så hvis du får en case med å opprette tusen på tusen av objekter med et hardt krav til responstid så må du kanskje være litt oppfinnsom. Personlig har jeg ikke erfart at load time weaving har gitt merkbart dårligere responstid.</p>
<p>En ting som kanskje er enda litt mer irriterende for deg som sitter og utvikler load-time-weavet kode er at du ikke kan bruke det sammen med ditt favoritt mock rammeverk. Den ene utsletter dessverre den andre og plutselig fungerer ingen tester. Det mock-rammeverket ditt trodde var et Person-objekt er ikke lengre et Person-objekt etter ltw. Nå er det et cglib objekt som utgir seg for å være et Person objekt. Personlig har jeg ikke funnet en smart måte å omgå dette på, og endt opp med å ikke teste med load time weaving men heller sørge for at enhets og integrasjonstester dekker det som dekkes skal slik at det blir middag.</p>
<p>For de som har lyst til å leke litt med load-time-weaving eller bare se et kjempeenkelt eksempel så har jeg snekret sammen et lite kodeeksempel her:<br />
<a href="http://github.com/judoole/ddd-ltw-spring">http://github.com/judoole/ddd-ltw-spring</a></p>
]]></content:encoded>
			<wfw:commentRss>http://open.bekk.no/2009/11/24/rent-og-pent-med-ltw/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Remote Log4J in Flex?</title>
		<link>http://open.bekk.no/2009/10/28/remote-log4j-in-flex/</link>
		<comments>http://open.bekk.no/2009/10/28/remote-log4j-in-flex/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 09:22:14 +0000</pubDate>
		<dc:creator>Ole Christian Langfjæran</dc:creator>
				<category><![CDATA[Grensesnittutvikling]]></category>
		<category><![CDATA[Webarkitektur]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[blazeds]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://open.bekk.no/?p=1247</guid>
		<description><![CDATA[Case: You&#8217;ve finally made that all-so-snazzy Flex application with DataGrids, Charts, transitions from here to the end of eternety, nice looking validators and all else you can think of. Also, you made it in no-time. The users are thrilled and so is the client. In other words, all is peachy in Rich Client Web Application [...]]]></description>
			<content:encoded><![CDATA[<p>Case: You&#8217;ve finally made that all-so-snazzy Flex application with DataGrids, Charts, transitions from here to the end of eternety, nice looking validators and all else you can think of. Also, you made it in no-time. The users are thrilled and so is the client. In other words, all is peachy in Rich Client Web Application Land.</p>
<p>Hadn&#8217;t been for those re-occuring complaints from the users that &#8220;An unknown exception has occured&#8221; message with a big warning label pops up from time to time. A nice little feature you made to hide all of those unexpected exceptions that can, but should not, occur in your application. All in all a good thing as we would like to spare the user the experience of reading an unpleasant stacktrace from an external webservice error. But YOU, on the other hand. You would love to get your hands on the stacktrace from that Error that shouldn&#8217;t happen. So, how?</p>
<p>In Java-Land this is usually done by incorporating some form of logging that logs messages to file or almost whatever you would like. Most preferred being <a title="Log4J homepage" href="http://logging.apache.org/log4j/1.2/index.html">Log4J</a>. Unfortunately I feel that a just-as-easy solution for Flex/Actionscript has yet to present itself. Until now. As a left-over artifact from the development of <a title="Spring Integration Home" href="http://www.springsource.org/spring-integration">Spring Integration</a>, the guys from Prana and Spring has made library called <a title="Home as3commons" href="http://code.google.com/p/as3-commons/">as3commons-logging</a>. The library mimics Log4j in many ways and makes an excellent job doing so. Adding the as3commons-logging swc to your project then makes remote logging a peach. Here&#8217;s howto:</p>
<h2>Some code</h2>
<p><strong>Step 1 of 3</strong><br />
Implement an ILoggerFactory like this. It&#8217;s responsibility will be to create Loggers for your classes:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> RemoteLoggerFactory implements ILoggerFactory
<span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">var</span> remote<span style="color: #339933;">:</span>RemoteObject<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> RemoteLoggerFactory<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">:</span>String<span style="color: #339933;">,</span> destination<span style="color: #339933;">:</span>String<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;remoteObjectLogger&quot;</span><span style="color: #339933;">,</span> fault<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">Function</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                remote <span style="color: #339933;">=</span> createRemote<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> destination<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                remote.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>FaultEvent.<span style="color: #660066;">FAULT</span><span style="color: #339933;">,</span> fault <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">?</span> onRemoteFault<span style="color: #339933;">:</span>fault<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> getLogger<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span>String<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>ILogger
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> RemoteLogger<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">,</span> remote<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009966; font-style: italic;">/** Creates a RemoteObject using SecureAMFChannel if https */</span>
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> createRemote<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">:</span>String<span style="color: #339933;">,</span> destination<span style="color: #339933;">:</span>String<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> RemoteObject
        <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> channelSet<span style="color: #339933;">:</span>ChannelSet <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ChannelSet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                channelSet.<span style="color: #660066;">addChannel</span><span style="color: #009900;">&#40;</span>isHttps<span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">new</span> SecureAMFChannel<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> url<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">new</span> AMFChannel<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> url<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #003366; font-weight: bold;">var</span> remoteService<span style="color: #339933;">:</span>RemoteObject <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RemoteObject<span style="color: #009900;">&#40;</span>destination<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                remoteService.<span style="color: #660066;">channelSet</span> <span style="color: #339933;">=</span> channelSet<span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">return</span> remoteService<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> isHttps<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">:</span>String<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> Boolean
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span> url.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;https&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009966; font-style: italic;">/** Default FaultHandler. Just traces the message. */</span>
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> onRemoteFault<span style="color: #009900;">&#40;</span>evt<span style="color: #339933;">:</span>FaultEvent<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">void</span>
        <span style="color: #009900;">&#123;</span>
                trace<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Could not log to server: &quot;</span><span style="color: #339933;">+</span>evt.<span style="color: #660066;">fault</span>.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Step 2 of 3</strong><br />
And then create the actual Logger which sends log messages to the backend, be that java, php, rails, .NET or name it.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> RemoteLogger <span style="color: #003366; font-weight: bold;">extends</span> DefaultLogger
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">protected</span> <span style="color: #003366; font-weight: bold;">var</span> _level<span style="color: #339933;">:</span>uint<span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">protected</span> <span style="color: #003366; font-weight: bold;">var</span> remote<span style="color: #339933;">:</span>Object<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> RemoteLogger<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span>String<span style="color: #339933;">,</span> remote<span style="color: #339933;">:</span>Object<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">remote</span> <span style="color: #339933;">=</span> remote<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	override <span style="color: #003366; font-weight: bold;">protected</span> <span style="color: #003366; font-weight: bold;">function</span> log<span style="color: #009900;">&#40;</span>level<span style="color: #339933;">:</span>uint<span style="color: #339933;">,</span> message<span style="color: #339933;">:</span>String<span style="color: #339933;">,</span> params<span style="color: #339933;">:</span>Array<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>level <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> <span style="color: #000066; font-weight: bold;">this</span>._level<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #006600; font-style: italic;">// add datetime</span>
			<span style="color: #003366; font-weight: bold;">var</span> msg<span style="color: #339933;">:</span>String <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;[&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;]&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// add the name given to this logger. Usually the Class name</span>
			msg <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;[&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;]&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// add message</span>
			msg <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot; - &quot;</span> <span style="color: #339933;">+</span> MessageUtil.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span>message<span style="color: #339933;">,</span> params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> logLevel<span style="color: #339933;">:</span>String <span style="color: #339933;">=</span> LogLevel.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span>level<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			remote.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>logLevel<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Step 3 of 3</strong><br />
Next instantiate your factory. Preferably as early as possible, so snapping in something like this at your Main mx:Application will do the trick.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">private</span> static <span style="color: #003366; font-weight: bold;">var</span> loggerSetup<span style="color: #339933;">:*</span> <span style="color: #339933;">=</span> LoggerFactory.<span style="color: #660066;">loggerFactory</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RemoteLoggerFactory<span style="color: #009900;">&#40;</span>ROOT_PATH<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;messagebroker/amf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And voila! It is now useable in any of your classes thiswise:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #003366; font-weight: bold;">private</span> static <span style="color: #003366; font-weight: bold;">const</span> logger<span style="color: #339933;">:</span>ILogger <span style="color: #339933;">=</span> LoggerFactory.<span style="color: #660066;">getClassLogger</span><span style="color: #009900;">&#40;</span>Jesus<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">function</span> Jesus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      logger.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Attention: We constructed Jesus.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>A dash of backend</h2>
<p>The last but not least is to have a backend that can receive the messages and log them in a human readable way for later error debugging.<br />
Why not splash out a java class with log4j? Well, this will do your trick:<br />
<strong>Step 3.5</strong></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RemoteObjectLogger
<span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> PRE_FLEX <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[FLEX]&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">final</span> Log logger <span style="color: #339933;">=</span> LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> log<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> level, <span style="color: #003399;">String</span> message<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INFO&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>level<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>PRE_FLEX <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DEBUG&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>level<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                        logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span>PRE_FLEX <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WARN&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>level<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                        logger.<span style="color: #006633;">warn</span><span style="color: #009900;">&#40;</span>PRE_FLEX <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ERROR&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>level<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                        logger.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span>PRE_FLEX <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;FATAL&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>level<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                        logger.<span style="color: #006633;">fatal</span><span style="color: #009900;">&#40;</span>PRE_FLEX <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                        logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span>PRE_FLEX <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;[&quot;</span> <span style="color: #339933;">+</span> level <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;] - &quot;</span> <span style="color: #339933;">+</span> message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Try it</h2>
<p>Would you like to see it in action? From top to bottom? Well I coded a small example for you to play with using Java as a backend. Svn the code from <a href="http://code.google.com/p/flex-code-examples/source/browse/#svn/trunk/src/spring-logging-blazeds">google-code</a>. Only prerequisite is <a href="http://maven.apache.org/download.html">Maven</a> installed. From there run compileAndRun and you are up and running!</p>
]]></content:encoded>
			<wfw:commentRss>http://open.bekk.no/2009/10/28/remote-log4j-in-flex/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
