# Yahoo! UI Library

### Logger Widget 2.8.2r1

Yahoo! UI Library > logger > LogWriter.js (source view)
Search:
Filters
Show Private Show Protected Show Deprecated

    /****************************************************************************/
    /****************************************************************************/
    /****************************************************************************/

    /**
     * The LogWriter class provides a mechanism to log messages through
     * YAHOO.widget.Logger from a named source.
     *
     * @class LogWriter
     * @constructor
     * @param sSource {String} Source of LogWriter instance.
     */
    YAHOO.widget.LogWriter = function(sSource) {
        if(!sSource) {
            YAHOO.log("Could not instantiate LogWriter due to invalid source.",
                "error", "LogWriter");
            return;
        }
        this._source = sSource;
     };

    /////////////////////////////////////////////////////////////////////////////
    //
    // Public methods
    //
    /////////////////////////////////////////////////////////////////////////////

     /**
     * Public accessor to the unique name of the LogWriter instance.
     *
     * @method toString
     * @return {String} Unique name of the LogWriter instance.
     */
    YAHOO.widget.LogWriter.prototype.toString = function() {
        return "LogWriter " + this._sSource;
    };

    /**
     * Logs a message attached to the source of the LogWriter.
     *
     * @method log
     * @param sMsg {String} The log message.
     * @param sCategory {String} Category name.
     */
    YAHOO.widget.LogWriter.prototype.log = function(sMsg, sCategory) {
        YAHOO.widget.Logger.log(sMsg, sCategory, this._source);
    };

    /**
     * Public accessor to get the source name.
     *
     * @method getSource
     * @return {String} The LogWriter source.
     */
    YAHOO.widget.LogWriter.prototype.getSource = function() {
        return this._source;
    };

    /**
     * Public accessor to set the source name.
     *
     * @method setSource
     * @param sSource {String} Source of LogWriter instance.
     */
    YAHOO.widget.LogWriter.prototype.setSource = function(sSource) {
        if(!sSource) {
            YAHOO.log("Could not set source due to invalid source.", "error", this.toString());
            return;
        }
        else {
            this._source = sSource;
        }
    };

    /////////////////////////////////////////////////////////////////////////////
    //
    // Private member variables
    //
    /////////////////////////////////////////////////////////////////////////////

    /**
     * Source of the LogWriter instance.
     *
     * @property _source
     * @type String
     * @private
     */
    YAHOO.widget.LogWriter.prototype._source = null;

Copyright © 2010 Yahoo! Inc. All rights reserved.