bc... [hack]
Home » Source Code » » logger.js

logger.js ( File view )

From:
  • By 2010-08-11
  • View(s):5
  • Download(s):0
  • Point(s): 1
			/*
	fvlogger v1.0
	(c) 2005 davidfmiller
	http://www.fivevoltlogic.com/code/fvlogger/
	see readme.txt for documentation
*/


// version number
var FVLOGGER_VERSION = '1.0';

// turn logging on or off;
var FVL_LOG_ON = true;

// all logging statements that whose level is greater than or equal to FVL_DEFAULT_LOG_LEVEL will be processed;
// all others will be ignored
var FVL_DEFAULT_LOG_LEVEL = FVL_DEBUG;

// the id of the node that will have the logging statements appended to it
var FVL_LOG_ID = 'fvlogger';

// the element that should be wrapped around the log messages
var FVL_LOG_ELEMENT = 'p';

/* the code that follows is */

// constants for logging levels
var FVL_DEBUG = 0;
var FVL_INFO = 1;
var FVL_WARN = 2;
var FVL_ERROR = 3;
var FVL_FATAL = 4;

// the css classes that will be applied to the logging elements
var FVL_LOG_CLASSES = new Array("debug","info","warn","error","fatal");

/* */

// retrieves the element whose id is equal to FVL_LOG_ID
function getLogger(id) {

	if (arguments.length == 0) {
 id = FVL_LOG_ID; 
}
	return document.getElementById(id);

}

function showDebug() {
 FVL_showMessages(FVL_DEBUG); 
}
function showInfo() {
 FVL_showMessages(FVL_INFO); 
}
function showWarn() {
 FVL_showMessages(FVL_WARN); 
}
function showError() {
 FVL_showMessages(FVL_ERROR); 
}
function showFatal() {
 FVL_showMessages(FVL_FATAL); 
}
function showAll() {
 FVL_showMessages(); 
}

// removes all logging information from the logging element
function eraseLog(ask) {

	var debug = getLogger();
	if (! debug) {
 return false; 
}

	if (ask && ! confirm("Are you sure you wish to erase the log?")) {

		return false;
	
}

	var ps = debug.getElementsByTagName(FVL_LOG_ELEMENT);
	var length = ps.length;
	for (var i = 0; i < length; i++) {
 debug.removeChild(ps[length - i - 1]); 
}
	return true;

}

function debug(message) {
 FVL_log("" + message, FVL_DEBUG); 
}
function warn(message) {
 FVL_log("" + message, FVL_WARN); 
}
function info(message) {
 FVL_log("" + message, FVL_INFO); 
}
function error(message) {
 FVL_log("" + message, FVL_ERROR);
}
//function fatal(message) {
 FVL_log("" + message, FVL_FATAL);
}

function windowError(message, url, line) {

	FVL_log('Error on line ' + line + ' of document ' + url + ': ' + message, FVL_FATAL);
	return true; //

}

// only override the window's error handler if we logging is turned on
if (FVL_LOG_ON) {

	window.onerror = windowError;

}

// 
function FVL_showMessages(level, hideOthers) {


//	alert('showing ' + level);

	var showAll = false;
	// if no level has been specified, use the default
	if (arguments.length == 0) {
 level = FVL_DEFAULT_LOG_LEVEL; showAll = true; 
}
	if (arguments.length < 2) {
 hideOthers = true; 
}

	// retrieve the element and current statements
	var debug = getLogger();
	if (! debug) {
 return false; 
}
	var ps = debug.getElementsByTagName("p");
	if (ps.length == 0) {
 return true; 
}

	// get the number of nodes in the list
	var l = ps.length; 

	// get the class name for the specified level
	var lookup = FVL_LOG_CLASSES[level]; 

	// loop through all logging statements/<p> elements...
	for (var i = l - 1; i >= 0; i--) {


		// hide all elements by default, if specified
		if (hideOthers) {
 hide(ps[i]); 
} 

		// get the class name for this <p>
		var c = getNodeClass(ps[i]);
//		alert(c);
//		alert("Node #" + i + "'s class is:" + c);
		if (c && c.indexOf(lookup) > -1 || showAll) {
 show(ps[i]); 
} 
	
}

}

// appends a statement to the logging element if the threshold level is exceeded
function FVL_log(message, level) {


	// check to make sure logging is turned on
	if (! FVL_LOG_ON) {
 return false; 
} 

	// retrieve the infrastructure
	if (arguments.length == 1) {
 level = FVL_INFO;
}
	if (level < FVL_DEFAULT_LOG_LEVEL) {
 return false; 
}
	var div = getLogger();
	if (! div) {
 return false; 
}

	// append the statement
	var p = document.createElement(FVL_LOG_ELEMENT);

	// this is a hack work around a bug in ie
	if (p.getAttributeNode("class")) {

		for (var i = 0; i < p.attributes.length; i++) {

			if (p.attributes[i].name.toUpperCase() == 'CLASS') {

				p.attributes[i].value = FVL_LOG_CLASSES[level];
			
}
		
}
	
} else {

		p.setAttribute("class", FVL_LOG_CLASSES[level]);
	
}
	var text = document.createTextNode(message);
	p.appendChild(text);
	div.appendChild(p);
	return true;

}

function exampleLogs() {

	// describe the four types of logging messages
	debug('Scatter debug messages throughout your code to provide a high-level overview of what your code is doing, such as which function is currently in scope and the values of loop counters.');
	info('Information messages are the meat and potatoes of logging messages; sprinkle them around to reveal more detailed information about your script\'s execution, such as the values of variables and function/method return values.');
	warn('Warning messages are used to indicate potentially hazardous situations, such as missing function arguments...');
	error('While error messages are used to indicate that something bad is about to happen; note that these kinds of errors are considered to be run-time errors, which are a different type of beast from the parse errors mentioned below.');

// generate an error to demonstrate the fatal error in ie and mozilla browsers
	a 

}

// show a node
function show(target) {

	target.style.display = "";
	return true;

}

// hide a node
function hide(target) {

	target.style.display = "none";
	return true;

}

// returns the class attribute of a node
function getNodeClass(obj) {

	var result = false;

	if (obj.getAttributeNode("class")) {

		result = obj.attributes.getNamedItem("class").value;
	
}
	return result;

}

use("jslib/jkl-floating.js");
function createLoggerDiv(divName) {

	// create a logger layer in the page.
	new Insertion.Top(divName,"<dl>"+
		"<dt id=\"fvlogger_header\">fvlogger</dt>"+
		"<dd class=\"all\"><a href=\"#fvlogger\" onclick=\"showAll();\" title=\"show all\" id=\"abcdef\">all</a></dd>"+
		"<dd class=\"debug\"><a href=\"#fvlogger\" onclick=\"showDebug();\" title=\"show debug\" id=\"showDebug\">debug</a></dd>"+
		"<dd class=\"info\"><a href=\"#fvlogger\" onclick=\"showInfo();\" title=\"show info\" id=\"showInfo\">info</a></dd>"+
		"<dd class=\"warn\"><a href=\"#fvlogger\" onclick=\"showWarn();\" title=\"show warnings\" id=\"showWarn\">warn</a></dd>"+
		"<dd class=\"error\"><a href=\"#fvlogger\" onclick=\"showError();\" title=\"show errors\" id=\"showError\">error</a></dd>"+
		"<dd class=\"fatal\"><a href=\"#fvlogger\" onclick=\"showFatal();\" title=\"show fatals\" id=\"showFatal\">fatal</a></dd>"+
		"<dd><a href=\"#fvlogger\" onclick=\"eraseLog(true);\" title=\"erase\">erase</a></dd>"+
		"</dl>");
	var float2 = new JKL.Floating(divName,"fvlogger_header");
	float2.opacity( 0.8, 0.5 );
	float2.start();
	float2.moveTo(400, 200);

}
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
auto_suggest.html1.09 kB03-12-07 00:11
crud.html1.68 kB03-12-07 00:11
03.00 B
2col_leftNav.css6.28 kB03-12-07 00:11
autosuggest.css335.00 B03-12-07 00:11
debug.png399.00 B03-12-07 00:11
error.png289.00 B03-12-07 00:11
fatal.png309.00 B03-12-07 00:11
info.png271.00 B03-12-07 00:11
logger.css1.88 kB03-12-07 00:11
magnet.png430.00 B03-12-07 00:11
site.css1.43 kB03-12-07 00:11
warn.png257.00 B03-12-07 00:11
03.00 B
auto_suggest.html.txt1.09 kB03-12-07 00:11
auto_suggest.js.txt669.00 B03-12-07 00:11
CountryList.java.txt3.00 kB03-12-07 00:11
crud.html.txt1.68 kB03-12-07 00:11
crud.js.txt1.40 kB03-12-07 00:11
crud.jst.txt755.00 B03-12-07 00:11
index.html.txt3.24 kB03-12-07 00:11
jst_demo.html.txt1.68 kB03-12-07 00:11
LabelValueBean.java.txt4.72 kB03-12-07 00:11
mvcPic.html.txt1.05 kB03-12-07 00:11
rdf.jst.txt284.00 B03-12-07 00:11
rss.jst.txt272.00 B03-12-07 00:11
rss_reader.html.txt1.20 kB03-12-07 00:11
rss_reader.js.txt642.00 B03-12-07 00:11
services.properties.txt168.00 B03-12-07 00:11
services.xml.txt435.00 B03-12-07 00:11
Test.java.txt17.36 kB03-12-07 00:11
TestBean.java.txt1.41 kB03-12-07 00:11
unit_test.html.txt1.03 kB03-12-07 00:11
unit_test.js.txt15.89 kB03-12-07 00:11
unit_test.jst.txt493.00 B03-12-07 00:11
unit_test_js.jst.txt765.00 B03-12-07 00:11
User.java.txt2.49 kB03-12-07 00:11
UserManager.java.txt2.04 kB03-12-07 00:11
web.xml.txt1.58 kB03-12-07 00:11
web.xml_no_spring.txt1.58 kB03-12-07 00:11
03.00 B
check.gif604.00 B03-12-07 00:11
debug.png399.00 B03-12-07 00:11
error.gif633.00 B03-12-07 00:11
error.png289.00 B03-12-07 00:11
fatal.png309.00 B03-12-07 00:11
info.png271.00 B03-12-07 00:11
magnet.png430.00 B03-12-07 00:11
swato_01.png5.22 kB03-12-07 00:11
swato_02.png13.94 kB03-12-07 00:11
swato_04.png7.94 kB03-12-07 00:11
swato_05.png14.42 kB03-12-07 00:11
swato_Layer-5-over.png27.12 kB03-12-07 00:11
swato_Layer_5.png28.45 kB03-12-07 00:11
wait.gif1.52 kB03-12-07 00:11
warn.png257.00 B03-12-07 00:11
index.html3.70 kB03-12-07 00:11
03.00 B
effects.js33.07 kB03-12-07 00:11
jkl-floating.js7.22 kB03-12-07 00:11
jkl-parsexml.js14.11 kB03-12-07 00:11
jkl-resizable.js5.05 kB03-12-07 00:11
json.js10.34 kB03-12-07 00:11
logger.js6.77 kB03-12-07 00:11
pop-it-menu.js4.44 kB03-12-07 00:11
prototype.js55.81 kB03-12-07 00:11
swato-engine.js5.06 kB03-12-07 00:11
swato-form.js3.00 kB03-12-07 00:11
swato-jst.js3.91 kB03-12-07 00:11
swato-select.js1.18 kB03-12-07 00:11
swato-suggest.js11.62 kB03-12-07 00:11
swato.js939.00 B03-12-07 00:11
window.js40.77 kB03-12-07 00:11
03.00 B
crud.jst744.00 B03-12-07 00:11
rdf.jst284.00 B03-12-07 00:11
rss.jst272.00 B03-12-07 00:11
unit_test.jst493.00 B03-12-07 00:11
unit_test_js.jst765.00 B03-12-07 00:11
jst_demo.html1.68 kB03-12-07 00:11
03.00 B
MANIFEST.MF106.00 B03-12-07 00:11
mvcPic.html1.05 kB03-12-07 00:11
rss_reader.html1.20 kB03-12-07 00:11
03.00 B
auto_suggest.js665.00 B03-12-07 00:11
crud.js1.41 kB03-12-07 00:11
portal.js4.66 kB03-12-07 00:11
rss_reader.js642.00 B03-12-07 00:11
unit_test.js15.89 kB03-12-07 00:11
swato.jar56.50 kB08-04-08 10:57
test.html18.36 kB03-12-07 00:11
unit_test.html1.03 kB03-12-07 00:11
03.00 B
03.00 B
03.00 B
03.00 B
JSONArray.class8.16 kB03-12-07 00:11
JSONObject$1.class199.00 B03-12-07 00:11
JSONObject$Null.class860.00 B03-12-07 00:11
JSONObject.class10.41 kB03-12-07 00:11
JSONTokener.class5.17 kB03-12-07 00:11
03.00 B
03.00 B
03.00 B
CountryList.class2.52 kB03-12-07 00:11
LabelValueBean$1.class825.00 B03-12-07 00:11
LabelValueBean.class2.15 kB03-12-07 00:11
LabelValueBeanTest.class1.88 kB03-12-07 00:11
ObjA.class571.00 B03-12-07 00:11
ObjB.class571.00 B03-12-07 00:11
Test$1.class565.00 B03-12-07 00:11
Test$2.class714.00 B03-12-07 00:11
Test$Foo.class231.00 B03-12-07 00:11
Test$InnerFoo.class643.00 B03-12-07 00:11
Test$InnerSubTestBean.class520.00 B03-12-07 00:11
Test$StaticInnerSubTestBean.class437.00 B03-12-07 00:11
Test$TestBeanInvocationHandler.class1.56 kB03-12-07 00:11
Test.class13.72 kB03-12-07 00:11
TestBean.class1.27 kB03-12-07 00:11
User.class1.65 kB03-12-07 00:11
UserManager.class2.27 kB03-12-07 00:11
JSONConverter.class8.00 kB03-12-07 00:11
JSONConverterTest$1.class240.00 B03-12-07 00:11
JSONConverterTest$TestBean.class1.73 kB03-12-07 00:11
JSONConverterTest.class6.13 kB03-12-07 00:11
03.00 B
JSONRequest.class2.96 kB03-12-07 00:11
JSONResponse.class2.41 kB03-12-07 00:11
JSONServlet.class4.00 kB03-12-07 00:11
PropsFileContext.class3.48 kB03-12-07 00:11
RequestAware.class198.00 B03-12-07 00:11
RequestParameterHolder.class2.36 kB03-12-07 00:11
RequestParameterRecorder.class2.17 kB03-12-07 00:11
RequestRedirector.class2.78 kB03-12-07 00:11
ServiceContext.class243.00 B03-12-07 00:11
SessionAware.class191.00 B03-12-07 00:11
SpringContext.class1.39 kB03-12-07 00:11
SwatoActionProxy.class4.86 kB03-12-07 00:11
SwatoVisible.class396.00 B03-12-07 00:11
03.00 B
Pipe.class2.02 kB03-12-07 00:11
Utils.class632.00 B03-12-07 00:11
services.properties168.00 B03-12-07 00:11
services.xml881.00 B03-12-07 00:11
03.00 B
commons-httpclient-2.0.2.jar220.09 kB03-12-07 00:11
commons-logging.jar37.12 kB03-12-07 00:11
spring-beans.jar213.99 kB03-12-07 00:11
spring-context.jar100.22 kB03-12-07 00:11
spring-core.jar71.98 kB03-12-07 00:11
web.xml1.58 kB03-12-07 00:11
...

logger.js (884.61 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D