by admin
I do a lot of work around Messaging in LCDS, and find myself writing the same code again and again to log all the Events that come from Producers and Consumers, and also in outputting these log messages in a nice format. I’ve used these two ActionScript classes for a few months now, but find myself constantly searching for them, so this is here for me, and if it helps anyone else that is a bonus.
There isn’t documentation, but they are simple components that should be fairly clear when reading the AS code.
LoggingTextArea
This is a subclass of the mx:TextArea and includes a ‘logger’ property of type Logger. It includes various helper methods to tie together the concepts of the Logging Framework of the Flex SDK into one class that I can just drop into a project to leverage all the categories/level etc and get my log info in a familar format.
Download LoggingTextArea.as
Sample Code
<mx:FormItem label="Log Level" direction="horizontal">
<mx:ComboBox id="logLevel"
dataProvider="{LoggingTextArea.LEVEL_STRINGS}"
change="logs.levelString = logLevel.selectedLabel"
selectedIndex="{LoggingTextArea.LEVEL_STRINGS.getItemIndex(logs.levelString)}"/>
<mx:Button label="Clear Logs" click="logs.clearLogs()"/>
</mx:FormItem>
.....
<local:LoggingTextArea id="logs"
levelString="{LoggingTextArea.LEVEL_INFO}"
width="100%" height="100%"/>
You can then use (i.e.) logs.logger.debug(“My Log Id: {0}”, clientId) to add messages to the LoggingTextArea.
LoggingMessageAgentDecorator
This utility you can just wrap around a Producer or a Consumer and give it a LoggingTextArea and it will configure all the Events that I normally want to listen for. There are a few other utility methods to send a text based message via a producer and also to change the defined channel that the message agent should use. The decorator also exposes some properties from the MessageAgent.channelSet that aren’t by definition bindable, but are via the decorator.
Download LoggingTextArea.as
Sample Code
<mx:FormItem label="Producer Channel" direction="horizontal">
<mx:ComboBox id="producerChannel"
dataProvider="{producerDecorator.channelIds}"
selectedIndex="{producerDecorator.channelIds.getItemIndex(producerDecorator.currentChannelId)}"/>
<mx:Button label="Change" click="producerDecorator.changeChannel(producerChannel.selectedLabel)"/>
</mx:FormItem>
....
<local:LoggingMessageAgentDecorator id="producerDecorator" loggingTextArea="{logs}">
<mx:Producer id="producer" destination="chat" />
</local:LoggingMessageAgentDecorator>
Tying it together
I also have a simple test MXML Applicatoin that shows how currently I tie them together. I tend to make this up as each time I am testing the actual implementation needs to be a little different each time, so just posting to show it being used.
Download TestChannels.mxml