sabinos.Log -> Documentation

- Class sabinos.Log

This is the main log class. This class is the one used to print all log message using the appenders internally.

Class

Return Name Description
sabinos.Log initialize(String caller [, Enumerable appenders]) Creates an instance of sabinos.Log with an string that will represent this particularly log object and an enumerable (array) of apprenders can also be added at the construction time.

Properties

Return Default Name Description
string null Caller Gets os sets a string value that represents this particularly log object
boolean true Enabled Gets os sets a boolean value that indicates if the log object is enabled. if false, no log output wil occur for this log
sabinos.Log.AppenderCollection - Appenders Gets or sets the appender collection for this log object

Printing Methods

The object parameters for all printing methods will be exaluated as explained in the sabinos.Log.Appenders documentation.

Return Function Description
- trace(String message [, Object object]) Prints an message with 'Trace' level.
- debug(String message [, Object object]) Prints an message with 'Debug' level.
- info(String message [, Object object]) Prints an message with 'Info' level.
- warn(String message [, Object object]) Prints an message with 'Warn' level.
- error(String message [, Object object]) Prints an message with 'Error' level.
- fatal(String message [, Object object]) Prints an message with 'Fatal' level.

Global scope variables

The variables bellow are global scope variables, and if any of then is changed it will affect all log objects loaded.

Return Name Description
string sabinos.Log.AppenderMisingException Exception that is thrown every time trying to manipulate appenders inside sabinos.Log class without loading the sabinos.Log.Appenders Javascript file
boolean sabinos.Log.Enabled Gets os sets a boolean value that indicates if loggin is enabled. if false, no log output wil occur for ALL log objects. The default value is true if the sabino.Log.Appenders file is correctly loaded, otherwise default value is false.

Top

- Class sabinos.Log.Level

This class defines all log levels contants. Levels are used by appenders to verify if they should or not print a certain message, and each message level is defined in the printing method that is being used, and can be verified at the sabinos.Log Class. Each one of then is a global scope variable and should not be changed.

Name Description
sabinos.Log.Level.Trace Defines the 'Trace' level
sabinos.Log.Level.Debug Defines the 'Debug' level
sabinos.Log.Level.Info Defines the 'Info' level
sabinos.Log.Level.Warn Defines the 'Warn' level
sabinos.Log.Level.Error Defines the 'Error' level
sabinos.Log.Level.Fatal Defines the 'Fatal' level
sabinos.Log.Level.All When used by an appender, means that the appender accepts all kinds of log printing levels

Top

- Class sabinos.Log.AppenderCollection

This class is used to hold all Appenders used by the current log. This collection is checked each time an printing method is called to fire the log action to each appender.

Instance

Return Name Description
sabinos.Log.AppenderCollection initialize([Enumerable appenders]) Creates an instance of sabinos.Log.AppenderCollection. Appenders can be set at construction time if wanted.

Methods

Return Function Description
- add(sabinos.Log.Appender.Base appender) Adds an appender to the collection
Enumerable _each() Iterates through the appenders collection

Top

- Namespace sabinos.Log.Appenders

This Namespace is reserved to all appender that came together with default configuration. All Appender inheritates from sabinos.Log.Appender.Base class and their definitions are particularities are listed bellow.

Top

- Class sabinos.Log.Appenders.Base

This class signature defines and can be used by all appenders bellow, in some cases their particularity at construction time, where some of then need extra parameters. More details about this class can be found at How to create you custom appender? section.

Instance

Return Name Description
sabinos.Log.Appenders.Base * initialize(string type, string pattern[, string level]) Creates an instance of sabinos.Log.Appenders.Base. The type parameter is a string representing the name of the inheritated class being used. The pattern is the string formated to ne used by the "getMessage" method. The level indicates which level the current appender is goingo to output messages, if not provided or null the default is sabinos.Log.Level.All

* All appenders classes that inheritate from this class must have their constructor calling the Base one as the follow:
initialize(pattern, level)
As the 'type' parameter is passes by the class internally.

Properties

Return Default Name Description
string - Type Gets os sets a string representing the name of the appender.
string - Pattern Gets os sets a string ith the message pattern that will be outputted.
sabinos.Log.Level sabinos.Log.Level.All Level Gets or sets the level(s) that the appender will output

Methods

All methods are internally used by sabinos.Log.AppenderCollection class only, their usage must be known only for better development of new appenders.

Return Function Description
boolean isLevelSelected(sabinos.Log.Level level) Gets a value indication if the appender is enabled for a given level. sabinos.Log class used this method to prevent unecessary log call to appenders.
object getObjects(Array args) Gets an object from the log call arguments.
string getMessage(Array args[, string message]) Gets a formated string from the appender pattern (if no message to be formated is provided in the getMessage call) after parsing the log call arguments.
- log This method is called by the sabinos.Log.AppenderCollection class to output the log message.

Message Pattern

Pattern parameter Replaced by
{message} Replaced by the message that is provided at each log method call
{caller} Replaced by the log caller string that identifies each log object
{level} Replaced by the level of the current log call
{time} Replaced by the time when the current log call eas made
{objJSON} Replaced by a JSON string representing the objects passed as parameter in the log call

Top

- Class sabinos.Log.Appenders.Alert

This appender outputs the log message as an alert message. This is not the best logging technique as it pauses all other javascripts from executing.

This appender has no particularity and can be used followig the Class sabinos.Log.Appenders.Base documentation

sabinos.Log.Appenders.Alert demo page

Top

- Class sabinos.Log.Appenders.Console

This appender outputs the log message to Firefox Firebug Extension Console.

This appender has no particularity and can be used followig the Class sabinos.Log.Appenders.Base documentation

sabinos.Log.Appenders.Console demo page

Top

- Class sabinos.Log.Appenders.Element

This appender outputs the log message to an HTML Element. If element is an <input type="text" ... > or <textarea> the log message will be appended to the value property of the element, otherwise the message will be appended to the innerHTML property of element, which is valid for DIVs os SPANs elements.

Instance

Return Name Description
sabinos.Log.Appenders.Element * initialize(string pattern, string level, string elementid) Creates an instance of sabinos.Log.Appenders.Element. Pattern e level are the same as described for Base class. The element parameter is the HTML element ID that will receive all log messages.

* This apender should only be created after the page DOM is loaded, otherwise the contrcutor will not find the element and no log will be outputed.

sabinos.Log.Appenders.Element demo page

Top

- Class sabinos.Log.Appenders.Event

This appender creates and fires an custom event using document.fire for each output message

Instance

Return Name Description
sabinos.Log.Appenders.Event * initialize(string pattern, string level, string eventName) Creates an instance of sabinos.Log.Appenders.Event. Pattern and level are the same as described for Base class. The eventName parameter is the name of the event that is going to be fired for the document element.

Memo object

Object that is received with the fired event by Event.observe prototype implementation.

Return Name Description
string Message Formatted log message
object Objects The object parameter passed after logging

sabinos.Log.Appenders.Event demo page

Top

- Class sabinos.Log.Appenders.Floating

Creats and floating div element that will be used to output the log message. This appender also provides a way to evaluate javascript at runtime.

Due to CSS interpretation differences for each browser this appender is displayed incorrectly by IE, but this is a known issue to be fixed in future version, however, the javascript funcionality is completely compatible.

* This apender should only be created after the page DOM is loaded

This appender has no particularity and can be used followig the Class sabinos.Log.Appenders.Base documentation

sabinos.Log.Appenders.Floating demo page

Top

- How to create you custom appender?

To be able to create and use your own appender you just have to inheritate a class from the sabinos.Log.Appenders.Base class like shown bellow:

//Creates the appender class which inheritates from sabinos.Log.Appenders.Base class
myCustomAppender = Class.create(sabinos.Log.Appenders.Base, {
    initialize : function($super, pattern, level) {
        //Call sabinos.Log.Appenders.Base class constructor
        $super('myCustomAppender', pattern, level);
    },
    //override the log method from the base appender to 
    // receive the log calls properly
    log : function(){
        //gets formatted message from base class implementation method.
        msg = this.getMessage(arguments);
        //gets objects that are being logged from base class implementation method.
        objs = this.getObjects(arguments);
        //output log messages calling some generic method
        myCustomMethod(msg, objs);
    }
});
    

Using you appender is as simple as creating it. You just have to add an instance of you appender class to the AppenderCollection of you log object

//Creates log object
var logger = new sabinos.Log('logger');

//Adds you custom appender to the log appender collection
logger.Appenders.add(
    new myCustomAppender('{message}', sabinos.Log.Level.All)
);
    

Top

Go back to sabinos.Log Page