QLog + splinklibrary Logging

May 30th, 2008

QLog is a java application which simply displays log messages. It enables to apply a filter to these messages so you can seek for a specific log or just display log messages which apply to the filter.

Because QLog is in fact a socket server it is also possible to display logs sent from an application which runs on a remote server. (This can be very handy). The greatest feature in my opionion is that messages sent to QLog can be equipped with a color for each kind of message (that is trace,info,debug,warn,error,fatal,...), so the messages look well arranged.

QLog view

In the whole QLog is a lot like powerflashers superb SocketOutputServer SOS but in contrast to SOS it is platform independent, it also runs on Mac Os X or Linux. (I developed it because i wanted to migrate to Ubuntu and I simply couldnt live without something like SOS)

QLog also integrates very well with the logging framework from splinklibrary. The splinklibrary logging framework comes with various ILogOutput implementations, so you can configure to which output destinations your logs are sent.
splinklibrary supports TraceOutput, FirebugOutput, SosOutput and QLogOutput out of the box. So you dont need to worry about any low level socket implementation details if you use QLog with splinklibrary.
One very useful feature of the sprinklibrary logging system is that if you run your application within the flash debug player, it adds the class- and methodname where the log originated from and if compiled with the -debug=true flag also the line number.

 
 
/**
 The Logger is configured once in a project. Each class which wants to
 log simply needs to add something like:
 private static const _logger:ILogger =
 LoggerProvider.getLogger("default", TheClassName);
 
*/
private function configureLogger():void
{
	var factory:ILoggerFactory = new LoggerFactory();
 
        /**
           It's possible to set various logger factories, so each one
           needs its own id
        */
	factory.setId("default");
 
        /**
         Logs within the specified range are sent to the log outputs
        */
	factory.setRange(new LogRange(LogLevel.TRACE, LogLevel.FATAL));
        /**
           DefaultOutputFormatter is used to format the log messages
           You can easily write and use your own IOutputFormatter
        */
	factory.setOuputFormatter(new DefaultOutputFormatter());
 
        /**
          Use different output strategies, here QLog and trace
          splinklibrary offers QLog, SOS, trace and Firebug LogOutput
          implementations. If you need something else, just implement
          the ILogOutput interface
        */
	factory.addLogOutput(new QLogOutput());
	factory.addLogOutput(new TraceOutput());
 
	LoggerProvider.addLoggerFactory(factory);
 
        /**
          Get a Logger and log something
        */
	_logger = LoggerProvider.getLogger("default", SampleApplicationClass);
        _logger.log(LogLevel.INFO, "Info");
        _logger.log(LogLevel.DEBUG, "Debug");
        _logger.log(LogLevel.ERROR, "Error");
}
 

Of course it should be quite simple to use Qlog with other Logging frameworks, or just to write a simple class to use it. splinklibararys QLogOutput should give a good impression how to do it.

Currently there is a stable QLog standalone version
Thanks to Fabian there is also a Eclipse Plugin version (very alpha) Update site: http://quui.com/update-site/
Here is a simple log4j appender class which enables to use QLog with the apache log4j framework for java.


No Comments »




splinklibrary 0.1.0 relased

May 26th, 2008

Today I released my actionscript 3 code library. It is the basic toolkit which I use in my as3 projects.

The splinklibrary core features are:
- event distribution
- queues
- reflection
- logging (log4j style)
- tweening (queue based)
- loading (queue based)

If you want to have a closer look at it check out the API docs

splinklibrary is hosted at google code. You can check it out from the google code svn here: http://splinklibrary.googlecode.com/svn/trunk/


No Comments »




AS2 EventDistributor

May 24th, 2008

Yes, I know, this is pretty old stuff, from the time before as3. Nevertheless I want to share my actionscript 2 event system for the unlucky fellows which still have to work with actionscript 2. If you know the as3 event system you will notice that EventDistributor is a lot like it, which should help to grasp quickly how to use it.

Originally I built EventDistributor to overcome the shortcomings of the way events were handled in as2. In as2 there were a couple of event systems, most well known probably the mx.EventDispatcher. Neither of these event systems could satisfy my needs, so I came up with my own solution for event distribution.

EventDistributor in contrast to the mx.EventDispatcher does not rely on static methods, it is glued to the class which needs to distribute events.
Therefore it is destroyed when the class utilizing it is destroyed. This is quite convenient, because if you destroy the class which fires events, every listener which is currently attached to it is removed too, so there is no need to write stuff like myEventDispatcher.removeListener("onSomeEvent", eventTargetFunction) over and over again.

mx.EventDispatcher is accessed trough static methods and therefore stores listeners in a static member array, which means that if you forget to remove a listener it will live on forever, which is pretty bad.

Furthermore EventDistributor encourages the usage of constants like Event.ON_COMPLETE rather then Strings like "onComplete" and is therefore much more error resistent.

EventDistributor provides all neccessary information for removing eventListeners with every distributed event. So you do not need to save function variables as class members to be able to remove listeners - you can remove them immediately after catching the event or remove all listeners by finalizing the class which makes use of the distributor.

EventDistributor distributes typed events, not generic objects like mx.EventDispatcher does. Because the events are typed you dont get into trouble when bubbeling events trough an application; Because EventDistributor encourages to create custom events by extending the Event base class or implementing the IEvent interface you always know about your events at compile time.

Well after the theory its time to have a look at how it is actually used:

 
/**
* The class which makes use of EventDistributor to distribute events
**/
class DistributingClass implements IDistributor
{
    private var _eventDistributor:EventDistributor;
    private var _targetMC:MovieClip;
 
    public function DistributingClass(targetMC:MovieClip)
    {
        _targetMC=targetMC;
        _eventDistributor=new EventDistributor();
        _eventDistributor.initialize(this);
        _targetMC.onRelease=Delegate.create(this,distribute);
    }
 
    private function distribute():Void
    {
        // ReleaseEvent extends Event or implements IEvent
        distributeEvent(new ReleaseEvent(ReleaseEvent.ON_RELEASE,
        "event_ID"));
    }
 
    private function addEventListener(type:String,func:Function){}:Void
 
    private function removeEventListener(type:String,func:Function){}:Void
 
    private function distributeEvent(eventObject:IEvent){}:Void
}
 
 
/**
* A custom event class which is distributed by DistributingClass
**/
class ReleaseEvent extends Event
{
    public static var ON_RELEASE : String="onRelease";
    private var _id:String;
 
    public function ReleaseEvent(type:String,id:String)
    {
        super(type);
        _id=id;
    }
 
    public function getId():String
    {
        return _id;
    }
}
 
 
/**
* A class which listens for ReleaseEvent objects distributed by
* DistributingClass
**/
class Listener
{
    private var _distributingClass:IDistributor;
 
    public function Listener(distributingClass:IDistributor)
    {
        _distributingClass = distributingClass
        _distributingClass.addEventListener(ReleaseEvent.ON_RELEASE,
        Delegate.create(this, onRelease);
    }
 
    private function onRelease(event:ReleaseEvent,listener:EventListener)
:Void
    {
        // in the case you want to unsubscribe immediately after the
        // event is caught:
        _distributingClass.removeEventListener(ReleaseEvent.ON_RELEASE,
        listener.getFunction());
        trace("event caught: "+event.getId();
    }
 
    public function finalize():Void
    {
        // in the case you want to destroy the class distributing events and
        // automatically remove all listeners
        _distributingClass.finalize();
    }
 
}
 

Download EventDistributor


No Comments »




DuDe

May 24th, 2008

Recently I discovered an interesting tool called DuDe. The author Richard Wettel describes DuDe as a 'text-based, language-independent code duplication (code clones) detector, gravitating around the concept of duplication chain.'


It is pretty simple to use; you start the jar, select a projects source folder and select the algorithm you want DuDe to use. Upon completion you can browse the results and learn which parts of your code could do with some optimizations.

I guess there are much more powerful tools for specific languages like java, but what makes DuDe shine brightly in my opinion is that it is language independent. So it works very well for actionscript source code or any other plain text files.


No Comments »




Hello world!

May 24th, 2008

Yes, i am a bit late, but finally I did it. After so many years of pondering whether to start a blog and 'go public' or not, I decided to just do it. So here it is: my brand new blog. Hope you will enjoy it.


No Comments »




Powered by WordPress