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

Removed Tag-Option

parent 9e965aab
No related branches found
No related tags found
1 merge request!1Update index.test.js, examples/all-options.js, examples/log-to-file.js,...
# log.js # log.js
A real simple logger application. A real simple logger application.
May Optional Log to A File and / or a Graylog-Server May Optional Log to A File.
## Installation ## Installation
...@@ -16,23 +16,12 @@ Note: The options Part may be omitted, as all parts are optional, but using the ...@@ -16,23 +16,12 @@ Note: The options Part may be omitted, as all parts are optional, but using the
### Methods ### Methods
* `log.info('This is an Information' )`
* `log.info('This is an Information' [, tags])` * `log.notice('This is a Notice' )`
* `log.notice('This is a Notice' [, tags])` * `log.warn('This is a Warning' )`
* `log.warn('This is a Warning' [, tags])` * `log.error('This is an Error' )`
* `log.error('This is an Error' [, tags])` * `log.fatal('This is a Fatal Message' )`
* `log.fatal('This is a Fatal Message' [, tags])` * `log.debug('This is a Debug Message' )`
* `log.debug('This is a Debug Message' [, tags])`
You may add Tags to a logline. These Tags may take the following forms:
* string = 'tag'
* string, seperated by whitespace = 'tag1 tag2 tag3'
* string, seperated by comma = 'tag1,tag2,tag3'
* array of strings = ['tag1', 'tag2', 'tag3']
These Tags will be added to the line with octothorpes added.
(#tag1 #tag2 #tag3)
### Options ### Options
......
...@@ -41,62 +41,50 @@ function Log (options) { ...@@ -41,62 +41,50 @@ function Log (options) {
} }
} }
} }
this.info = function (message, tags) { this.info = function (message) {
if (this.loglevel >= this.levels.INFO) { if (this.loglevel >= this.levels.INFO) {
return this.log('INFO', message, tags) return this.log('INFO', message)
} else { } else {
return '' return ''
} }
} }
this.notice = function (message, tags) { this.notice = function (message) {
if (this.loglevel >= this.levels.NOTICE) { if (this.loglevel >= this.levels.NOTICE) {
return this.log('NOTICE', message, tags) return this.log('NOTICE', message)
} else { } else {
return '' return ''
} }
} }
this.fatal = function (message, tags) { this.fatal = function (message) {
if (this.loglevel >= this.levels.FATAL) { if (this.loglevel >= this.levels.FATAL) {
return this.log('FATAL', message, tags) return this.log('FATAL', message)
} else { } else {
return '' return ''
} }
} }
this.warn = function (message, tags) { this.warn = function (message) {
if (this.loglevel >= this.levels.WARN) { if (this.loglevel >= this.levels.WARN) {
return this.log('WARN', message, tags) return this.log('WARN', message)
} else { } else {
return '' return ''
} }
} }
this.error = function (message, tags) { this.error = function (message) {
if (this.loglevel >= this.levels.ERROR) { if (this.loglevel >= this.levels.ERROR) {
return this.log('ERROR', message, tags) return this.log('ERROR', message)
} else { } else {
return '' return ''
} }
} }
this.debug = function (message, tags) { this.debug = function (message) {
if (this.loglevel >= this.levels.DEBUG) { if (this.loglevel >= this.levels.DEBUG) {
return this.log('DEBUG', message, tags) return this.log('DEBUG', message)
} else { } else {
return '' return ''
} }
} }
this.log = function (tag, message, tags) { this.log = function (tag, message) {
let tadd = '' let msg = this.getDate() + '\t' + this.hostname + '\t' + this.name + '\t' + tag + '\t' + message
if (typeof tags !== 'undefined') {
if (Array.isArray(tags)) {
tadd = ' #' + tags.join(' #')
} else if (tags.includes(' ')) {
tadd = ' #' + tags.split(' ').join(' #')
} else if (tags.includes(',')) {
tadd = ' #' + tags.split(',').join(' #')
} else {
tadd = ' #' + tags
}
}
let msg = this.getDate() + '\t' + this.hostname + '\t' + this.name + '\t' + tag + '\t' + message + tadd
switch (tag) { switch (tag) {
case 'INFO': case 'INFO':
console.info(msg) console.info(msg)
......
{ {
"name": "lib-log", "name": "lib-log",
"version": "1.1.0", "version": "2.0.0",
"description": "A simple Logger with Options!", "description": "A simple Logger with Options!",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment