diff --git a/README.md b/README.md index f9752bef668752352da8bca47651c7529eea361c..92ce93fa08e7c96b1f96ac6311986a3743c31e45 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ May Optional Log to A File. ## Usage -`const Log = require('log')` +`const Log = require('log')` `let log = new Log(options)` Note: The options Part may be omitted, as all parts are optional, but using the name is recommended, as without it, the package-name will be used @@ -29,6 +29,15 @@ Note: The options Part may be omitted, as all parts are optional, but using the name: 'Name of App. Default: Name of BaseFolder', hostname: 'Server Hostname, Default: os.hostname()', file: 'File to Append Log to', + graylog: { + active: 'true or false', + servers: [ + { + server: 'graylog-server', + port: 'graylog-port' + } + ] + }, path: 'Path Logfile located', loglevel: 'Minimal LogLevel. Default: WARN' } diff --git a/index.js b/index.js index c2e6e086c14144e6f1a6050867b43d63be4edff9..86b9f5d66b89a54da0a552ab8d565922d582fa81 100644 --- a/index.js +++ b/index.js @@ -43,6 +43,15 @@ function Log (options) { } } } + if (this.options.graylog && this.options.graylog.active) { + this.graylog2 = require('graylog2') + this.graylogger = new this.graylog2.graylog({ // eslint-disable-line new-cap + servers: this.options.graylog.servers, + hostname: this.hostname, + facility: this.name + }) + } + this.info = function (message) { if (this.loglevel >= this.levels.INFO) { return this.log('INFO', message) @@ -116,6 +125,30 @@ function Log (options) { } }) } + if (this.options.graylog && this.options.graylog.active) { + switch (tag) { + case 'INFO': + this.graylogger.info(message) + break + case 'NOTICE': + this.graylogger.notice(message) + break + case 'WARN': + this.graylogger.warning(message) + break + case 'ERROR': + this.graylogger.error(message) + break + case 'FATAL': + this.graylogger.critical(message) + break + case 'DEBUG': + this.graylogger.debug(message) + break + default: + this.graylogger.notice(message) + } + } return msg } this.getDate = function () { diff --git a/package-lock.json b/package-lock.json index b08133aa9d3c4f7b643d8df550da50486b762753..604d0c6bc113e6a55db0fc84555f3ef6a88c9638 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lib-log", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2027,6 +2027,11 @@ "integrity": "sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ==", "dev": true }, + "graylog2": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/graylog2/-/graylog2-0.2.1.tgz", + "integrity": "sha512-vjysakwOhrAqMeIvSK0WZcmzKvkpxY6pCfT9QqtdSVAidPFIynuin7adqbdFp9MCCTbTE402WIxvg8cph5OWTA==" + }, "growly": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", diff --git a/package.json b/package.json index 019a3948bab1550f8a2b13a1b51f93573adea623..c7f0441f77bbc04a37a36e1208de953c53333dbd 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,10 @@ { "name": "lib-log", - "version": "2.0.0", + "version": "2.1.0", "description": "A simple Logger with Options!", "main": "index.js", "scripts": { - "test": "jest tests/index.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": "jest tests/index.test.js" }, "author": "Dominik Sigmund <sigmund.dominik@googlemail.com> (https://webdad.eu)", "license": "ISC", @@ -14,7 +12,9 @@ "type": "git", "url": "https://it-devops-01.br-edv.brnet.int/argos/log" }, - "dependencies": {}, + "dependencies": { + "graylog2": "^0.2.1" + }, "devDependencies": { "jest": "^24.9.0" }