Development JavaScript DHTML




Logger Widget :: Writing Logs









    
        

Logger Widget :: Writing Logs


    

    
        
        
        
            
                
                    
                        

Writing Log Messages From Your Code


                        

In this example, we instanatiate a simple LogReader to display log
                        messages. We use the global method YAHOO.log() to write simple messages,
                        and we also instantiate a LogWriter instance to write messages from a
                        custom-named source.


                        


                            Log this message


                        


                            Log this message


                        


                            Log this message


                        


                            Log this message


                        


                            Log this message (not supported in Opera, Safari)


                        


                            
                            Log this message with this category


                        


                            Generate some messages from a named source


                    

                    
                

            
            
             
                
                
                    

Sample Code


                    
                    
                    //No custom CSS styles were defined
                    //No custom markup was defined
                    // Instantiate a logreader and a logwriter
                    myLogReader = new YAHOO.widget.LogReader(null,{top:"10%",right:"10px"});
                    myLogWriter = new YAHOO.widget.LogWriter("myWriter");
                    // You can call the global function YAHOO.log() anytime, anywhere
                    YAHOO.log("Yahoo! is great"); // defaults to type "info"
                    YAHOO.log("Here is a warning", "warn");
                    YAHOO.log("Some error has occurred", "error");
                    YAHOO.log("Use timers to profile your code", "time");
                    myLogWriter.log("something","info");
                    myLogWriter.log("something","warn");
                    myLogWriter.log("something","error");
                    myLogWriter.log("something","time");
                    myLogWriter.log("something","custom");
                    
                    
                
                
             
        
        
    









YAHOO.example.LogWriter = function() {
    var myLogReader;
    var myLogWriter;
    return {
        init: function() {
            // Instantiate a logreader and a logwriter
            myLogReader = new YAHOO.widget.LogReader(null,{top:"10%",right:"10px"});
            myLogWriter = new YAHOO.widget.LogWriter("myWriter");
            // You can call the global function YAHOO.log() anytime, anywhere
            YAHOO.log("Yahoo! is great"); // defaults to type "info"
            YAHOO.log("Here is a warning", "warn");
            YAHOO.log("Some error has occurred", "error");
            YAHOO.log("Use timers to profile your code", "time");
            // Define interesting moments that cause log messages to be written
            var oSelf = YAHOO.example.LogWriter;
            YAHOO.util.Event.addListener(document.getElementById('btn_loginfo'),'click',oSelf.onLogInfoClick);
            YAHOO.util.Event.addListener(document.getElementById('btn_logwarn'),'click',oSelf.onLogWarnClick);
            YAHOO.util.Event.addListener(document.getElementById('btn_logerror'),'click',oSelf.onLogErrorClick);
            YAHOO.util.Event.addListener(document.getElementById('btn_logtime'),'click',oSelf.onLogTimeClick);
            YAHOO.util.Event.addListener(document.getElementById('btn_logcustom'),'click',oSelf.onLogCustomClick);
            YAHOO.util.Event.addListener(document.getElementById('btn_logsource'),'click',oSelf.onSourceWriterClick);
        },
        hideAllReaders: function() {
            myLogReader.hide();
        },
        showAllReaders: function() {
            myLogReader.show();
        },
        createNewLogWriter: function(source) {
            // You can instantiate your own named logwriter and use it to write log messages
            var newWriter = new YAHOO.widget.LogWriter(source);
            newWriter.log("Doing great!"); // defaults to type "info"
            newWriter.log("Giving a warning", "warn");
            newWriter.log("Throwing an error", "error");
            newWriter.log("Timing some code", "time");
        },
        onSourceWriterClick: function() {
            YAHOO.example.LogWriter.createNewLogWriter(document.getElementById('yui-log-inputsource').value);
        },
        onLogInfoClick: function() {
            myLogWriter.log(document.getElementById('yui-log-inputinfo').value,'info');
        },
        onLogWarnClick: function() {
            myLogWriter.log(document.getElementById('yui-log-inputwarn').value,'warn');
        },
        onLogErrorClick: function() {
            myLogWriter.log(document.getElementById('yui-log-inputerror').value,'error');
        },
        onLogTimeClick: function() {
            myLogWriter.log(document.getElementById('yui-log-inputtime').value,'time');
        },
        onLogCustomClick: function() {
            myLogWriter.log(document.getElementById('yui-log-inputcustommsg').value,document.getElementById('yui-log-inputcustomtype').value);
        }
    };
}();
YAHOO.util.Event.addListener(this,'load',YAHOO.example.LogWriter.init);



dp.SyntaxHighlighter.HighlightAll('code');



           
       
yui.zip( 3,714 k)