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) { function Log (options) {
this.levels = {
'DEBUG': 5,
'INFO': 4,
'NOTICE': 3,
'WARN': 2,
'ERROR': 1,
'FATAL': 0
}
this.options = options || {} 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) { if (this.options.name) {
this.name = this.options.name this.name = this.options.name
} else { } else {
...@@ -15,22 +28,46 @@ function Log (options) { ...@@ -15,22 +28,46 @@ function Log (options) {
this.fs = require('fs') this.fs = require('fs')
} }
this.info = function (message, tags) { this.info = function (message, tags) {
if (this.loglevel >= this.levels.INFO) {
return this.log('INFO', message, tags) return this.log('INFO', message, tags)
} else {
return ''
}
} }
this.notice = function (message, tags) { this.notice = function (message, tags) {
if (this.loglevel >= this.levels.NOTICE) {
return this.log('NOTICE', message, tags) return this.log('NOTICE', message, tags)
} else {
return ''
}
} }
this.fatal = function (message, tags) { this.fatal = function (message, tags) {
if (this.loglevel >= this.levels.FATAL) {
return this.log('FATAL', message, tags) return this.log('FATAL', message, tags)
} else {
return ''
}
} }
this.warn = function (message, tags) { this.warn = function (message, tags) {
if (this.loglevel >= this.levels.WARN) {
return this.log('WARN', message, tags) return this.log('WARN', message, tags)
} else {
return ''
}
} }
this.error = function (message, tags) { this.error = function (message, tags) {
if (this.loglevel >= this.levels.ERROR) {
return this.log('ERROR', message, tags) return this.log('ERROR', message, tags)
} else {
return ''
}
} }
this.debug = function (message, tags) { this.debug = function (message, tags) {
if (this.loglevel >= this.levels.DEBUG) {
return this.log('DEBUG', message, tags) return this.log('DEBUG', message, tags)
} else {
return ''
}
} }
this.log = function (tag, message, tags) { this.log = function (tag, message, tags) {
let tadd = '' let tadd = ''
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"description": "A simple Logger with Options!", "description": "A simple Logger with Options!",
"main": "index.js", "main": "index.js",
"scripts": { "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" "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", "author": "Dominik Sigmund",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment