/*
    Look-Look Javascript Logger
    This is logging code to allow for easier debugging of Javascript code.

    Below is the core code for the logging system.  Users will usually want to use
    more simple methods for creating and logging LL_LogEvents.

    When using this code in your pages, there needs to be a hooks file referenced as well as a
    core file (which actually contains the code of the logging system).
*/

LL_LogEvent = function() {
    this.date = new Date();
    this.component = 'undefined';
    this.level = 'INFO';
    this.message = '';
}

var LL_Logger = Class.create();
Object.extend(LL_Logger.prototype, {
    initialize: function() {
        this.levels = ['TRACE', 'DEBUG', 'WARN', 'INFO', 'ERROR', 'FATAL'];
        this.ignoredComponents = new Array();
        this.enabled = true;

        this.levelStatus = new Object();
        this.levels.each(function(level) {this.levelStatus[level] = true;}.bind(this));

        this.events = new Array();

        this.listener = null;
        this.listeners = new Array();
    },

/*
    The main entry point for adding a logging event.
    Application code will usually use a method that will
    create the event (LL_LogEvent) for them automagically.
*/
    log: function(event) {
        if (!this.enabled || !this.isLevelEnabled(event.level))
            return;

        this.events.push(event);

        this.notifyListeners(event);
    },

    isLevelEnabled: function(level) {
        return this.levelStatus[level];
    },

    notifyListeners: function(event) {
        if (this.listener)
            this.listener.logEvent(event);
    },

    toString: function() {
        var string = '';

        for(var i = 0; i < this.events.length; i++) {
            var event = this.events[i];

            string += '<p>'

            string += event.date;
            string += " : ";
            string += event.level;
            string += " : ";
            string += event.component;
            string += " : ";
            string += event.message;

            string += '</p>'

        }

        return string;
    }


});