Last active
December 10, 2015 20:08
-
-
Save jcolebrand/4485677 to your computer and use it in GitHub Desktop.
log4js implementation as taken on this date. Just for purposes of seeing it in the cloud.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Log4js = { | |
version : "1.0", | |
applicationStartDate : new Date(), | |
loggers : {}, | |
getLogger : function (categoryName) { | |
if (!(typeof categoryName == "string")) { | |
categoryName = "[default]"; | |
} | |
if (!Log4js.loggers[categoryName]) { | |
Log4js.loggers[categoryName] = new Log4js.Logger(categoryName); | |
} | |
return Log4js.loggers[categoryName]; | |
}, | |
getDefaultLogger : function () { | |
return Log4js.getLogger("[default]"); | |
}, | |
attachEvent : function (element, name, observer) { | |
if (element.addEventListener) { | |
element.addEventListener(name, observer, false); | |
} else if (element.attachEvent) { | |
element.attachEvent('on' + name, observer); | |
} | |
}, | |
extend : function (destination, source) { | |
for (property in source) { | |
destination[property] = source[property]; | |
} | |
return destination; | |
}, | |
bind : function (fn, object) { | |
return function () { | |
return fn.apply(object, arguments); | |
}; | |
}, | |
Level : function (level, levelStr) { | |
this.level = level; | |
this.levelStr = levelStr; | |
} | |
}; | |
Log4js.Level.prototype = { | |
toLevel : function (sArg, defaultLevel) { | |
if (typeof sArg == "string") { | |
var sArg = sArg.toUpperCase(); | |
} | |
switch (sArg) { | |
case 'ALL': | |
case ALL_INT: | |
return Log4js.Level.ALL; | |
case 'DEBUG': | |
case DEBUG_INT: | |
return Log4js.Level.DEBUG; | |
case 'INFO': | |
case INFO_INT: | |
return Log4js.Level.INFO; | |
case 'WARN': | |
case WARN_INT: | |
return Log4js.Level.WARN; | |
case 'ERROR': | |
case ERROR_INT: | |
return Log4js.Level.ERROR; | |
case 'FATAL': | |
case FATAL_INT: | |
return Log4js.Level.FATAL; | |
case 'OFF': | |
case OFF_INT: | |
return Log4js.Level.OFF; | |
case 'TRACE': | |
case TRACE_INT: | |
return Log4js.Level.TRACE; | |
default: | |
return defaultLevel; | |
} | |
}, | |
toString : function () { | |
return this.levelStr; | |
}, | |
valueOf : function () { | |
return this.level; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Log4js = { | |
version : "1.0", | |
applicationStartDate : new Date(), | |
loggers : {}, | |
getLogger : function (categoryName) { | |
if (!(typeof categoryName == "string")) { | |
categoryName = "[default]"; | |
} | |
if (!Log4js.loggers[categoryName]) { | |
Log4js.loggers[categoryName] = new Log4js.Logger(categoryName); | |
} | |
return Log4js.loggers[categoryName]; | |
}, | |
getDefaultLogger : function () { | |
return Log4js.getLogger("[default]"); | |
}, | |
attachEvent : function (element, name, observer) { | |
if (element.addEventListener) { | |
element.addEventListener(name, observer, false); | |
} else if (element.attachEvent) { | |
element.attachEvent('on' + name, observer); | |
} | |
}, | |
extend : function (destination, source) { | |
for (property in source) { | |
destination[property] = source[property]; | |
} | |
return destination; | |
}, | |
bind : function (fn, object) { | |
return function () { | |
return fn.apply(object, arguments); | |
}; | |
}, | |
Level : function (level, levelStr) { | |
this.level = level; | |
this.levelStr = levelStr; | |
this.prototype = { | |
toLevel : function (sArg, defaultLevel) { | |
if (typeof sArg == "string") { | |
var sArg = sArg.toUpperCase(); | |
} | |
switch (sArg) { | |
case 'ALL': | |
case ALL_INT: | |
return Log4js.Level.ALL; | |
case 'DEBUG': | |
case DEBUG_INT: | |
return Log4js.Level.DEBUG; | |
case 'INFO': | |
case INFO_INT: | |
return Log4js.Level.INFO; | |
case 'WARN': | |
case WARN_INT: | |
return Log4js.Level.WARN; | |
case 'ERROR': | |
case ERROR_INT: | |
return Log4js.Level.ERROR; | |
case 'FATAL': | |
case FATAL_INT: | |
return Log4js.Level.FATAL; | |
case 'OFF': | |
case OFF_INT: | |
return Log4js.Level.OFF; | |
case 'TRACE': | |
case TRACE_INT: | |
return Log4js.Level.TRACE; | |
default: | |
return defaultLevel; | |
} | |
}, | |
toString : function () { | |
return this.levelStr; | |
}, | |
valueOf : function () { | |
return this.level; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment