diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml old mode 100644 new mode 100755 diff --git a/.npmignore b/.npmignore old mode 100644 new mode 100755 diff --git a/.npmrc b/.npmrc old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 7f84ebe34c18609e56b99507c44d3894e5fb5335..71426c598ff25841594b4ed8cf3860b737796650 --- a/README.md +++ b/README.md @@ -5,38 +5,53 @@ May Optional Log to A File and a graylog-server via http or udp. ## Installation -- `npm install --save @plastdev/config` +- `npm install --save @general/config` ## Usage -`const Log = require('@plastdev/log')` +`const Log = require('@general/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 ### Methods -* `log.info('This is an Information' )` -* `log.notice('This is a Notice' )` -* `log.warn('This is a Warning' )` -* `log.error('This is an Error' )` -* `log.fatal('This is a Fatal Message' )` -* `log.debug('This is a Debug Message' )` +- `log.info('This is an Information' )` +- `log.notice('This is a Notice' )` +- `log.warn('This is a Warning' )` +- `log.error('This is an Error' )` +- `log.fatal('This is a Fatal Message' )` +- `log.debug('This is a Debug Message' )` + +You may also add any number of any parameter. The objects will be concatenated using your custom delimeter and stringified. + +e.g.: + +`log.info('this', ['array', 8], 4, {type:'test'})` + +will logged as + +__YYYY-MM-DDTHH:ii:ss SERVER INFO this ["array",8] 4 {"type": "test"} ### Options ```json { - 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', - mode: 'http or udp, defaults to udp', - server: 'graylog-server', - port: 'graylog-port' - }, - path: 'Path Logfile located', - loglevel: 'Minimal LogLevel. Default: WARN' + "name": "Name of App. Default: Name of BaseFolder", + "hostname": "Server Hostname, Default: os.hostname()", + "file": "'File to Append Log to", + "path": "Path Logfile located", + "loglevel": "Minimal LogLevel. Default: WARN", + "delimeter": "How to join multiple outputs. Default: (a single space)", + "graylog": { + "active": "true or false", + "mode": "http or udp, defaults to udp", + "server": "graylog-server", + "port": "graylog-port" + } } ``` + +### Examples + +Check the Examples to get a Feeling about the possibilities. diff --git a/examples/all-options.js b/examples/all-options.js old mode 100644 new mode 100755 diff --git a/examples/http-server.js b/examples/graylog-http-server.js old mode 100644 new mode 100755 similarity index 100% rename from examples/http-server.js rename to examples/graylog-http-server.js diff --git a/examples/udp-server.js b/examples/graylog-udp-server.js old mode 100644 new mode 100755 similarity index 100% rename from examples/udp-server.js rename to examples/graylog-udp-server.js diff --git a/examples/log-to-file.js b/examples/log-to-file.js old mode 100644 new mode 100755 diff --git a/examples/log-to-graylog-http.js b/examples/log-to-graylog-http.js old mode 100644 new mode 100755 diff --git a/examples/log-to-graylog-udp.js b/examples/log-to-graylog-udp.js old mode 100644 new mode 100755 diff --git a/examples/multi-object-logging.js b/examples/multi-object-logging.js new file mode 100755 index 0000000000000000000000000000000000000000..da54ba4320a4439572527983b4a2f23e33697fd3 --- /dev/null +++ b/examples/multi-object-logging.js @@ -0,0 +1,11 @@ +const Log = require('../index.js') + +let log = new Log({ + name: 'Sample-Application', + hostname: 'test-server', + loglevel: 'DEBUG' +}) + +log.info({this: 'is json'}) +log.info('This is an Information', 8, ['array', 45, 'mixed', 34.456], {also:'json'}) +log.info('test', 'test', 'test') \ No newline at end of file diff --git a/examples/no-options.js b/examples/no-options.js old mode 100644 new mode 100755 diff --git a/index.d.ts b/index.d.ts old mode 100644 new mode 100755 index bdd3bca74db2c69078d93c040755b68112f0ca01..861237127ab10fd9f74f01aab3d5df7b4f047f3e --- a/index.d.ts +++ b/index.d.ts @@ -5,9 +5,9 @@ export = Log; /*~ Write your module's methods and properties in this class */ declare class Log { constructor(config?: any); - info(message: string): string; - notice(message: string): string; - debug(message: string): string; - warning(message: string): string; - log(message: string): string; + info(...message: any): string; + notice(...message: any): string; + debug(...message: any): string; + warning(...message: any): string; + log(...message: any): string; } diff --git a/index.js b/index.js old mode 100644 new mode 100755 index 9050ab689d2c2f217546e8dd9d47a18e08e81785..aec90c9c18746f57451578e9b68b0727bc8c7343 --- a/index.js +++ b/index.js @@ -13,6 +13,11 @@ function Log (options) { } else { this.loglevel = 2 } + if (this.options.delimeter) { + this.delimeter = this.options.delimeter + } else { + this.delimeter = ' ' + } if (this.options.name) { this.name = this.options.name } else { @@ -36,7 +41,9 @@ function Log (options) { this.fs = require('fs') this.path = require('path') try { - if (!this.fs.existsSync(this.options.path)) this.fs.mkdirSync(this.options.path, { recursive: true }) + if (!this.fs.existsSync(this.options.path)) { + this.fs.mkdirSync(this.options.path, { recursive: true }) + } } catch (error) { throw new Error('Could not create path ' + this.options.path + '\n' + error.toString()) } @@ -50,50 +57,61 @@ function Log (options) { } } } - this.info = function (message) { + this.info = function (...message) { if (this.loglevel >= this.levels.INFO) { - return this.log('INFO', message) + return this.log('INFO', ...message) } else { return '' } } - this.notice = function (message) { + this.notice = function (...message) { if (this.loglevel >= this.levels.NOTICE) { - return this.log('NOTICE', message) + return this.log('NOTICE', ...message) } else { return '' } } - this.fatal = function (message) { + this.fatal = function (...message) { if (this.loglevel >= this.levels.FATAL) { - return this.log('FATAL', message) + return this.log('FATAL', ...message) } else { return '' } } - this.warn = function (message) { + this.warn = function (...message) { if (this.loglevel >= this.levels.WARN) { - return this.log('WARN', message) + return this.log('WARN', ...message) } else { return '' } } - this.error = function (message) { + this.error = function (...message) { if (this.loglevel >= this.levels.ERROR) { - return this.log('ERROR', message) + return this.log('ERROR', ...message) } else { return '' } } - this.debug = function (message) { + this.debug = function (...message) { if (this.loglevel >= this.levels.DEBUG) { - return this.log('DEBUG', message) + return this.log('DEBUG', ...message) } else { return '' } } - this.log = function (tag, message) { - let msg = this.getDate() + '\t' + this.hostname + '\t' + this.name + '\t' + tag + '\t' + message + this.log = function (tag, ...message) { + let msgString = '' + if (message.length > 1) { + let self = this + msgString = message.reduce(function (acc, cur) { + return acc + self.delimeter + self.objectToString(cur); + }) + } else { + msgString = this.objectToString(message[0]) + } + + + let msg = this.getDate() + '\t' + this.hostname + '\t' + this.name + '\t' + tag + '\t' + msgString switch (tag) { case 'INFO': console.info(msg) @@ -152,6 +170,21 @@ function Log (options) { var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1) return localISOTime.split('.')[0].trim() } + this.objectToString = function (obj) { + let add = '' + try { + if (typeof obj === 'string' || obj instanceof String) { + add = obj + } else if(obj instanceof Array) { + add = obj.toString() + } elseĆ { + add = JSON.stringify(obj) + } + } catch (error) { + add = obj.toString() + } + return add + } return this } module.exports = Log diff --git a/index.test.js b/index.test.js old mode 100644 new mode 100755 index 4894de18e83947f99b7ea5febdeed3544339ce10..588a2a1ff66000f75d757a8b570d2b0d664c7016 --- a/index.test.js +++ b/index.test.js @@ -1,5 +1,4 @@ /* global it, describe, beforeEach, afterEach */ -const assert = require('assert') const os = require('os') const path = require('path') const fs = require('fs') @@ -15,299 +14,305 @@ const name = 'testapp' let file = 'testfile' const filePath = '/tmp' -let orginialFile -let log -let line -let testline +function createLogLine(level, msg) { + return getDate() + '\t' + hostname + '\t@general/log\t' + level + '\t' + msg +} + + describe('@general/log', () => { - describe(': No Options', () => { - beforeEach(() => { - console.log('create Object') - log = new LOG() - }) - afterEach(() => { - console.log('destroy Object') - log = undefined - }) - describe(': Info', () => { - it('should output empty line - standard log-level without options is warn', () => { - line = log.info('testline') - assert.equal(line, '') - }) - }) - describe(': Notice', () => { - it('should output empty line - standard log-level without options is warn', () => { - line = log.notice('testline') - assert.equal(line, '') - }) - }) - describe(': Warn', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tWARN\ttestline' - line = log.warn('testline') - assert.equal(line, testline) - }) - }) - describe(': Error', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tERROR\ttestline' - line = log.error('testline') - assert.equal(line, testline) - }) - }) - describe(': Fatal', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tFATAL\ttestline' - line = log.fatal('testline') - assert.equal(line, testline) - }) - }) - describe(': Debug', () => { - it('should output the given Line', () => { - line = log.debug('testline') - assert.equal(line, '') - }) - }) + describe('Contructor', () => { + it('should log default with no options', () => { + let log = new LOG(); + expect(log.loglevel).toBe(2) + expect(log.delimeter).toBe(' ') + expect(log.name).toBe('@general/log') + expect(log.hostname).toBe(hostname) + }) + it('should use option hostname', () => { + let log = new LOG({ + hostname: 'test' + }); + expect(log.loglevel).toBe(2) + expect(log.delimeter).toBe(' ') + expect(log.name).toBe('@general/log') + expect(log.hostname).toBe('test') + }) + it('should use option name', () => { + let log = new LOG({ + name: 'test' + }); + expect(log.loglevel).toBe(2) + expect(log.delimeter).toBe(' ') + expect(log.name).toBe('test') + expect(log.hostname).toBe(hostname) + }) + it('should use option delimeter', () => { + let log = new LOG({ + delimeter: ';' + }); + expect(log.loglevel).toBe(2) + expect(log.delimeter).toBe(';') + expect(log.name).toBe('@general/log') + expect(log.hostname).toBe(hostname) + }) + it('should use option loglevel', () => { + let log = new LOG({ + loglevel: 'FATAL' + }); + expect(log.loglevel).toBe(0) + expect(log.delimeter).toBe(' ') + expect(log.name).toBe('@general/log') + expect(log.hostname).toBe(hostname) + }) + it.todo('should use option graylog') + it.todo('should use option file') + it.todo('should use option path') }) - describe(': Hostname Set', () => { - beforeEach(() => { - console.log('create Object') - log = new LOG({ - hostname: manualhostname - }) - }) - afterEach(() => { - console.log('destroy Object') - log = undefined - }) - describe(': Info', () => { - it('should output the given Line', () => { - line = log.info('testline') - assert.equal(line, '') - }) - }) - describe(': Notice', () => { - it('should output the given Line', () => { - line = log.notice('testline') - assert.equal(line, '') - }) - }) - describe(': Warn', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + manualhostname + '\t@general/log\tWARN\ttestline' - line = log.warn('testline') - assert.equal(line, testline) - }) - }) - describe(': Error', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + manualhostname + '\t@general/log\tERROR\ttestline' - line = log.error('testline') - assert.equal(line, testline) - }) - }) - describe(': Fatal', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + manualhostname + '\t@general/log\tFATAL\ttestline' - line = log.fatal('testline') - assert.equal(line, testline) - }) - }) - describe(': Debug', () => { - it('should output the given Line', () => { - line = log.debug('testline') - assert.equal(line, '') - }) + describe('log by level', () => { + it('should log fatal only if level is appropriate', () => { + let log = new LOG({loglevel: 'FATAL'}); + let logged = log.fatal('test') + expect(logged).toBe(createLogLine('FATAL', 'test')) + + log = new LOG({loglevel: 'ERROR'}); + logged = log.fatal('test') + expect(logged).toBe(createLogLine('FATAL', 'test')) + + log = new LOG({loglevel: 'WARN'}); + logged = log.fatal('test') + expect(logged).toBe(createLogLine('FATAL', 'test')) + + log = new LOG({loglevel: 'NOTICE'}); + logged = log.fatal('test') + expect(logged).toBe(createLogLine('FATAL', 'test')) + + log = new LOG({loglevel: 'INFO'}); + logged = log.fatal('test') + expect(logged).toBe(createLogLine('FATAL', 'test')) + + log = new LOG({loglevel: 'DEBUG'}); + logged = log.fatal('test') + expect(logged).toBe(createLogLine('FATAL', 'test')) + }) + it('should log error only if level is appropriate', () => { + let log = new LOG({loglevel: 'FATAL'}); + let logged = log.error('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'ERROR'}); + logged = log.error('test') + expect(logged).toBe(createLogLine('ERROR', 'test')) + + log = new LOG({loglevel: 'WARN'}); + logged = log.error('test') + expect(logged).toBe(createLogLine('ERROR', 'test')) + + log = new LOG({loglevel: 'NOTICE'}); + logged = log.error('test') + expect(logged).toBe(createLogLine('ERROR', 'test')) + + log = new LOG({loglevel: 'INFO'}); + logged = log.error('test') + expect(logged).toBe(createLogLine('ERROR', 'test')) + + log = new LOG({loglevel: 'DEBUG'}); + logged = log.error('test') + expect(logged).toBe(createLogLine('ERROR', 'test')) + }) + it('should log warnings only if level is appropriate', () => { + let log = new LOG({loglevel: 'FATAL'}); + let logged = log.warn('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'ERROR'}); + logged = log.warn('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'WARN'}); + logged = log.warn('test') + expect(logged).toBe(createLogLine('WARN', 'test')) + + log = new LOG({loglevel: 'NOTICE'}); + logged = log.warn('test') + expect(logged).toBe(createLogLine('WARN', 'test')) + + log = new LOG({loglevel: 'INFO'}); + logged = log.warn('test') + expect(logged).toBe(createLogLine('WARN', 'test')) + + log = new LOG({loglevel: 'DEBUG'}); + logged = log.warn('test') + expect(logged).toBe(createLogLine('WARN', 'test')) + }) + it('should log notices only if level is appropriate', () => { + let log = new LOG({loglevel: 'FATAL'}); + let logged = log.notice('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'ERROR'}); + logged = log.notice('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'WARN'}); + logged = log.notice('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'NOTICE'}); + logged = log.notice('test') + expect(logged).toBe(createLogLine('NOTICE', 'test')) + + log = new LOG({loglevel: 'INFO'}); + logged = log.notice('test') + expect(logged).toBe(createLogLine('NOTICE', 'test')) + + log = new LOG({loglevel: 'DEBUG'}); + logged = log.notice('test') + expect(logged).toBe(createLogLine('NOTICE', 'test')) + }) + it('should log info only if level is appropriate', () => { + let log = new LOG({loglevel: 'FATAL'}); + let logged = log.info('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'ERROR'}); + logged = log.info('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'WARN'}); + logged = log.info('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'NOTICE'}); + logged = log.info('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'INFO'}); + logged = log.info('test') + expect(logged).toBe(createLogLine('INFO', 'test')) + + log = new LOG({loglevel: 'DEBUG'}); + logged = log.info('test') + expect(logged).toBe(createLogLine('INFO', 'test')) + }) + it('should log debug only if level is appropriate', () => { + let log = new LOG({loglevel: 'FATAL'}); + let logged = log.debug('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'ERROR'}); + logged = log.debug('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'WARN'}); + logged = log.debug('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'NOTICE'}); + logged = log.debug('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'INFO'}); + logged = log.debug('test') + expect(logged).toBe('') + + log = new LOG({loglevel: 'DEBUG'}); + logged = log.debug('test') + expect(logged).toBe(createLogLine('DEBUG', 'test')) }) }) - describe(': Name Set', () => { - beforeEach(() => { - console.log('create Object') - log = new LOG({ - name: name - }) - }) - afterEach(() => { - console.log('destroy Object') - log = undefined - }) - describe(': Info', () => { - it('should output the given Line', () => { - line = log.info('testline') - assert.equal(line, '') - }) - }) - describe(': Notice', () => { - it('should output the given Line', () => { - line = log.notice('testline') - assert.equal(line, '') - }) - }) - describe(': Warn', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t' + name + '\tWARN\ttestline' - line = log.warn('testline') - assert.equal(line, testline) - }) - }) - describe(': Error', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t' + name + '\tERROR\ttestline' - line = log.error('testline') - assert.equal(line, testline) - }) - }) - describe(': Fatal', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t' + name + '\tFATAL\ttestline' - line = log.fatal('testline') - assert.equal(line, testline) - }) - }) - describe(': Debug', () => { - it('should output the given Line', () => { - line = log.debug('testline') - assert.equal(line, '') - }) + describe('log messages', () => { + it('should log a string as is', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug('test') + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\ttest' + expect(logged).toBe(expected) + }) + it('should log multiple strings with the delimeter', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug('test', 'test', 'test') + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\ttest test test' + expect(logged).toBe(expected) + }) + it('should log a number as a string', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug(8) + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\t8' + expect(logged).toBe(expected) + }) + it('should log a float as a string', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug(8.23) + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\t8.23' + expect(logged).toBe(expected) + }) + it('should log a boolean as a string', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug(true) + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\ttrue' + expect(logged).toBe(expected) + }) + it('should log an array as a string', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug(['test', 'test']) + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\ttest,test' + expect(logged).toBe(expected) + }) + it('should log a json-object as a string', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug({some: 'value'}) + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\t{"some":"value"}' + expect(logged).toBe(expected) + }) + it('should log a mixed entry as a string', () => { + let log = new LOG({loglevel: 'DEBUG'}); + let logged = log.debug('test', 7, 3.45, false, ['value', 'more'], {some: 'value'}) + let expected = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\ttest 7 3.45 false value,more {"some":"value"}' + expect(logged).toBe(expected) }) }) - describe(': File Set', () => { - beforeEach(() => { - console.log('create Object') - log = new LOG({ - path: filePath, - file: file - }) - orginialFile = file - file = path.join(filePath, file) - try { - fs.accessSync(file, fs.constants.R_OK | fs.constants.W_OK) - } catch (error) { - fs.writeFileSync(file, '', { flag: 'wx' }) // Create File if not exists - } - }) - afterEach(() => { - console.log('destroy Object') - log = undefined - fs.truncateSync(file) // Clean Up, clear contents - file = orginialFile - }) - describe(': Info', () => { - it('should output the given Line to the file', function (done) { - log.info('testline') - setTimeout(() => { - line = fs.readFileSync(file, 'utf-8') - assert.equal(line, '') - done() - }, 10) - }) - }) - describe(': Notice', () => { - it('should output the given Line to the file', function (done) { - log.notice('testline') - setTimeout(() => { - line = fs.readFileSync(file, 'utf-8') - assert.equal(line, '') - done() - }, 10) - }) - }) - describe(': Warn', () => { - it('should output the given Line to the file', function (done) { - testline = getDate() + '\t' + hostname + '\t@general/log\tWARN\ttestline\n' - log.warn('testline') - setTimeout(() => { - line = fs.readFileSync(file, 'utf-8') - assert.equal(line, testline) - done() - }, 10) - }) - }) - describe(': Error', () => { - it('should output the given Line to the file', function (done) { - testline = getDate() + '\t' + hostname + '\t@general/log\tERROR\ttestline\n' - log.error('testline') - setTimeout(() => { - line = fs.readFileSync(file, 'utf-8') - assert.equal(line, testline) - done() - }, 10) - }) - }) - describe(': Fatal', () => { - it('should output the given Line to the file', function (done) { - testline = getDate() + '\t' + hostname + '\t@general/log\tFATAL\ttestline\n' - log.fatal('testline') - setTimeout(() => { - line = fs.readFileSync(file, 'utf-8') - assert.equal(line, testline) - done() - }, 10) - }) - }) - describe(': Debug', () => { - it('should output the given Line to the file', function (done) { - log.debug('testline') - setTimeout(() => { - line = fs.readFileSync(file, 'utf-8') - assert.equal(line, '') - done() - }, 10) - }) + describe('log to file', () => { + it('should create the folder if not exists', () => { + let logPath = os.tmpdir() + '/log-test' + Math.floor(Math.random() * 1000) + expect(() => { + fs.accessSync(logPath, fs.constants.R_OK | fs.constants.W_OK) + }).toThrow(); + let log = new LOG({ + path: logPath, + file: 'test.log' + }); + expect(fs.accessSync(logPath, fs.constants.R_OK | fs.constants.W_OK)).toBeUndefined() + }) + it('should create the file if not exists', () => { + let logPath = os.tmpdir() + '/log-test' + Math.floor(Math.random() * 1000) + expect(() => { + fs.accessSync(logPath + '/test.log', fs.constants.R_OK | fs.constants.W_OK) + }).toThrow(); + let log = new LOG({ + path: logPath, + file: 'test.log' + }); + expect(fs.accessSync(logPath + '/test.log', fs.constants.R_OK | fs.constants.W_OK)).toBeUndefined() + }) + it('should log to a file', (done) => { + let logPath = os.tmpdir() + '/log-test' + Math.floor(Math.random() * 1000) + let log = new LOG({ + path: logPath, + file: 'test.log' + }); + log.fatal('filetest') + let expected = getDate() + '\t' + hostname + '\t@general/log\tFATAL\tfiletest\n' + setTimeout(()=>{ + expect(fs.readFileSync(logPath + '/test.log', 'utf8')).toBe(expected) + done() + },500 ) + }) }) - describe(': Loglevel DEBUG Set', () => { - beforeEach(() => { - console.log('create Object') - log = new LOG({ - loglevel: 'DEBUG' - }) - }) - afterEach(() => { - console.log('destroy Object') - log = undefined - }) - describe(': Info', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tINFO\ttestline' - line = log.info('testline') - assert.equal(line, testline) - }) - }) - describe(': Notice', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tNOTICE\ttestline' - line = log.notice('testline') - assert.equal(line, testline) - }) - }) - describe(': Warn', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tWARN\ttestline' - line = log.warn('testline') - assert.equal(line, testline) - }) - }) - describe(': Error', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tERROR\ttestline' - line = log.error('testline') - assert.equal(line, testline) - }) - }) - describe(': Fatal', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tFATAL\ttestline' - line = log.fatal('testline') - assert.equal(line, testline) - }) - }) - describe(': Debug', () => { - it('should output the given Line', () => { - testline = getDate() + '\t' + hostname + '\t@general/log\tDEBUG\ttestline' - line = log.debug('testline') - assert.equal(line, testline) - }) - }) + describe('log to graylog', () => { + it.todo('should log to graylog via udp') + it.todo('should log to graylog via http') }) + // TODO: formatting + // TODO: log to loki + // TODO: add mutation test }) diff --git a/package-lock.json b/package-lock.json old mode 100644 new mode 100755 diff --git a/package.json b/package.json old mode 100644 new mode 100755