Skip to content
Snippets Groups Projects
Commit 3b5f30ab authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Added LogLevel-Control

parent fe4d9b6d
No related branches found
No related tags found
1 merge request!1Update index.test.js, examples/all-options.js, examples/log-to-file.js,...
function Log (options) {
this.levels = {
'DEBUG': 5,
'INFO': 4,
'NOTICE': 3,
'WARN': 2,
'ERROR': 1,
'FATAL': 0
}
this.options = options || {}
if (this.options.loglevel) { // DEBUG, INFO, NOTICE, WARN, ERROR, FATAL
this.loglevel = this.levels[this.options.loglevel]
} else {
this.loglevel = 2
}
if (this.options.name) {
this.name = this.options.name
} else {
......@@ -15,22 +28,46 @@ function Log (options) {
this.fs = require('fs')
}
this.info = function (message, tags) {
return this.log('INFO', message, tags)
if (this.loglevel >= this.levels.INFO) {
return this.log('INFO', message, tags)
} else {
return ''
}
}
this.notice = function (message, tags) {
return this.log('NOTICE', message, tags)
if (this.loglevel >= this.levels.NOTICE) {
return this.log('NOTICE', message, tags)
} else {
return ''
}
}
this.fatal = function (message, tags) {
return this.log('FATAL', message, tags)
if (this.loglevel >= this.levels.FATAL) {
return this.log('FATAL', message, tags)
} else {
return ''
}
}
this.warn = function (message, tags) {
return this.log('WARN', message, tags)
if (this.loglevel >= this.levels.WARN) {
return this.log('WARN', message, tags)
} else {
return ''
}
}
this.error = function (message, tags) {
return this.log('ERROR', message, tags)
if (this.loglevel >= this.levels.ERROR) {
return this.log('ERROR', message, tags)
} else {
return ''
}
}
this.debug = function (message, tags) {
return this.log('DEBUG', message, tags)
if (this.loglevel >= this.levels.DEBUG) {
return this.log('DEBUG', message, tags)
} else {
return ''
}
}
this.log = function (tag, message, tags) {
let tadd = ''
......
......@@ -4,7 +4,8 @@
"description": "A simple Logger with Options!",
"main": "index.js",
"scripts": {
"test": "nyc --reporter=html --reporter=text mocha -- tests/test.js && rsync --remove-source-files -av --progress ./coverage ./docs/ && rm -Rf ./coverage",
"test" : "mocha tests/test.js",
"test-coverage": "nyc --reporter=html --reporter=text mocha -- tests/test.js && rsync --remove-source-files -av --progress ./coverage ./docs/ && rm -Rf ./coverage",
"test-graphics": "nyc --reporter=html --reporter=text mocha -R mochawesome -- tests/test.js && rsync --remove-source-files -av --progress ./coverage ./docs/ && rm -Rf ./coverage && rsync --remove-source-files -av --progress ./mochawesome-report ./docs/ && rm -Rf ./mochawesome-report"
},
"author": "Dominik Sigmund",
......
const Log = require('../index.js')
let log = new Log()
log.info('This is an Information', 'info')
log.notice('This is a Notice', 'notice system ping')
log.warn('This is a Warning', 'some,tags,added')
log.error('This is an Error', ['tag', 'error', 'crit', 'api'])
log.debug('This is a Debug Message')
log.fatal('This is a Fatal Message')
const Log = require('../index.js')
let log = new Log()
log.info('This is an Information', 'info')
log.notice('This is a Notice', 'notice system ping')
log.warn('This is a Warning', 'some,tags,added')
log.error('This is an Error', ['tag', 'error', 'crit', 'api'])
log.debug('This is a Debug Message')
log.fatal('This is a Fatal Message')
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment