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

Merge branch 'patch_ENOENT' into 'master'

patch ENOENT + update tests + change mocha to jest + update docu

See merge request argos/log!1
parents 33c3c360 a8c8c820
No related branches found
No related tags found
1 merge request!1Update index.test.js, examples/all-options.js, examples/log-to-file.js,...
Pipeline #7259 failed
......@@ -4,8 +4,7 @@ A real simple logger application.
May Optional Log to A File.
## Installation
`npm install --save git+ssh://tfs-br-prod.br-edv.brnet.int:22/ArGOS/lib/_git/log`
`npm install --save git+ssh://git@it-devops-01.br-edv.brnet.int:argos/log.git`
## Usage
......@@ -30,6 +29,7 @@ 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',
path: 'Path Logfile located',
loglevel: 'Minimal LogLevel. Default: WARN'
}
```
\ No newline at end of file
......@@ -27,15 +27,17 @@ function Log (options) {
if (this.options.file) {
this.fs = require('fs')
this.path = require('path')
this.options.file = this.path.resolve(this.options.file)
if (!this.fs.lstatSync(this.options.file).isFile()) {
throw new Error(this.options.file + ' is not a File...')
try {
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())
}
try {
this.fs.accessSync(this.options.file, this.fs.constants.R_OK | this.fs.constants.W_OK)
this.fs.accessSync(this.path.join(this.options.path, this.options.file), this.fs.constants.R_OK | this.fs.constants.W_OK)
} catch (err) {
try {
this.fs.writeFileSync(this.options.file, '')
this.fs.writeFileSync(this.path.join(this.options.path, this.options.file), '', { flag: 'wx' })
} catch (err) {
throw new Error('Could not Create File ' + this.options.file + '\n' + err.toString())
}
......@@ -107,8 +109,8 @@ function Log (options) {
default:
console.log(msg)
}
if (this.options.file) {
this.fs.appendFile(this.options.file, msg + '\n', function (error) {
if (this.options.path && this.options.file) {
this.fs.appendFile(this.path.join(this.options.path, this.options.file), msg + '\n', function (error) {
if (error) {
console.error('Cannot write to File ' + this.options.file)
}
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -4,7 +4,7 @@
"description": "A simple Logger with Options!",
"main": "index.js",
"scripts": {
"test" : "mocha tests/test.js",
"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"
},
......@@ -12,14 +12,10 @@
"license": "ISC",
"repository": {
"type": "git",
"url" : "https://github.com/WebDaD/lib-log"
"url": "https://it-devops-01.br-edv.brnet.int/argos/log"
},
"dependencies": {},
"devDependencies": {
"mocha": "^5.2.0",
"mochawesome": "^3.0.3",
"nyc": "^13.0.1",
"stryker": "^0.29.5",
"stryker-api": "^0.21.2"
"jest": "^24.9.0"
}
}
......@@ -2,7 +2,8 @@ const Log = require('../index.js')
let log = new Log({
name: 'Sample-File',
file: 'file.log'
file: 'file.log',
path: '/temp'
})
log.info('This is an Information')
......
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')
/* global it, describe, beforeEach, afterEach */
const assert = require('assert')
const os = require('os')
const path = require('path')
const fs = require('fs')
const LOG = require(path.join(__dirname, '../index.js'))
const hostname = os.hostname()
function getDate () {
var tzoffset = (new Date()).getTimezoneOffset() * 60000 // offset in milliseconds
var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1)
return localISOTime.split('.')[0].trim()
}
const manualhostname = 'testhost'
const name = 'testapp'
let file = 'testfile'
const filePath = '/tmp'
let orginialFile
let log
let line
let testline
describe('Log.js', () => {
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 + '\tlib-log\tWARN\ttestline'
line = log.warn('testline')
assert.equal(line, testline)
})
})
describe(': Error', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + hostname + '\tlib-log\tERROR\ttestline'
line = log.error('testline')
assert.equal(line, testline)
})
})
describe(': Fatal', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + hostname + '\tlib-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(': 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 + '\tlib-log\tWARN\ttestline'
line = log.warn('testline')
assert.equal(line, testline)
})
})
describe(': Error', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + manualhostname + '\tlib-log\tERROR\ttestline'
line = log.error('testline')
assert.equal(line, testline)
})
})
describe(': Fatal', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + manualhostname + '\tlib-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(': 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(': 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 + '\tlib-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 + '\tlib-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 + '\tlib-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(': 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 + '\tlib-log\tINFO\ttestline'
line = log.info('testline')
assert.equal(line, testline)
})
})
describe(': Notice', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + hostname + '\tlib-log\tNOTICE\ttestline'
line = log.notice('testline')
assert.equal(line, testline)
})
})
describe(': Warn', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + hostname + '\tlib-log\tWARN\ttestline'
line = log.warn('testline')
assert.equal(line, testline)
})
})
describe(': Error', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + hostname + '\tlib-log\tERROR\ttestline'
line = log.error('testline')
assert.equal(line, testline)
})
})
describe(': Fatal', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + hostname + '\tlib-log\tFATAL\ttestline'
line = log.fatal('testline')
assert.equal(line, testline)
})
})
describe(': Debug', () => {
it('should output the given Line', () => {
testline = getDate() + '\t' + hostname + '\tlib-log\tDEBUG\ttestline'
line = log.debug('testline')
assert.equal(line, testline)
})
})
})
})
/* global it, describe, beforeEach, afterEach */
const assert = require('assert')
const os = require('os')
const path = require('path')
const fs = require('fs')
const LOG = require(path.join(__dirname, '../index.js'))
const hostname = os.hostname()
function getDate () {
var tzoffset = (new Date()).getTimezoneOffset() * 60000 // offset in milliseconds
var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1)
return localISOTime.split('.')[0].trim()
}
const manualhostname = 'testhost'
const name = 'testapp'
const file = '/tmp/testfile'
let log
let line
let testline
describe('Log.js', function () {
describe(': No Options', function () {
beforeEach('create Object', function () {
log = new LOG()
})
afterEach('destroy Object', function () {
log = undefined
})
describe(': Info', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\tlog\tINFO\ttestline'
line = log.info('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\tlog\tINFO\ttestline #tag1 #tag2 #tag3'
line = log.info('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.info('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.info('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Notice', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\tlog\tNOTICE\ttestline'
line = log.notice('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\tlog\tNOTICE\ttestline #tag1 #tag2 #tag3'
line = log.notice('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.notice('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.notice('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Warn', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\tlog\tWARN\ttestline'
line = log.warn('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\tlog\tWARN\ttestline #tag1 #tag2 #tag3'
line = log.warn('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.warn('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.warn('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Error', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\tlog\tERROR\ttestline'
line = log.error('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\tlog\tERROR\ttestline #tag1 #tag2 #tag3'
line = log.error('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.error('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.error('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Fatal', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\tlog\tFATAL\ttestline'
line = log.fatal('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\tlog\tFATAL\ttestline #tag1 #tag2 #tag3'
line = log.fatal('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.fatal('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.fatal('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Debug', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\tlog\tDEBUG\ttestline'
line = log.debug('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\tlog\tDEBUG\ttestline #tag1 #tag2 #tag3'
line = log.debug('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.debug('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.debug('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
})
describe(': Hostname Set', function () {
beforeEach('create Object', function () {
log = new LOG({
hostname: manualhostname
})
})
afterEach('destroy Object', function () {
log = undefined
})
describe(': Info', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tINFO\ttestline'
line = log.info('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tINFO\ttestline #tag1 #tag2 #tag3'
line = log.info('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.info('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.info('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Notice', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tNOTICE\ttestline'
line = log.notice('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tNOTICE\ttestline #tag1 #tag2 #tag3'
line = log.notice('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.notice('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.notice('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Warn', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tWARN\ttestline'
line = log.warn('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tWARN\ttestline #tag1 #tag2 #tag3'
line = log.warn('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.warn('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.warn('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Error', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tERROR\ttestline'
line = log.error('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tERROR\ttestline #tag1 #tag2 #tag3'
line = log.error('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.error('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.error('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Fatal', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tFATAL\ttestline'
line = log.fatal('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tFATAL\ttestline #tag1 #tag2 #tag3'
line = log.fatal('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.fatal('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.fatal('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Debug', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tDEBUG\ttestline'
line = log.debug('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + manualhostname + '\tlog\tDEBUG\ttestline #tag1 #tag2 #tag3'
line = log.debug('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.debug('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.debug('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
})
describe(': Name Set', function () {
beforeEach('create Object', function () {
log = new LOG({
name: name
})
})
afterEach('destroy Object', function () {
log = undefined
})
describe(': Info', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tINFO\ttestline'
line = log.info('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tINFO\ttestline #tag1 #tag2 #tag3'
line = log.info('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.info('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.info('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Notice', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tNOTICE\ttestline'
line = log.notice('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tNOTICE\ttestline #tag1 #tag2 #tag3'
line = log.notice('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.notice('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.notice('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Warn', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tWARN\ttestline'
line = log.warn('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tWARN\ttestline #tag1 #tag2 #tag3'
line = log.warn('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.warn('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.warn('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Error', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tERROR\ttestline'
line = log.error('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tERROR\ttestline #tag1 #tag2 #tag3'
line = log.error('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.error('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.error('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Fatal', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tFATAL\ttestline'
line = log.fatal('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tFATAL\ttestline #tag1 #tag2 #tag3'
line = log.fatal('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.fatal('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.fatal('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
describe(': Debug', function () {
it('should output the given Line', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tDEBUG\ttestline'
line = log.debug('testline')
assert.equal(line, testline)
})
it('should output the given Line with Tags', function () {
testline = getDate() + '\t' + hostname + '\t' + name + '\tDEBUG\ttestline #tag1 #tag2 #tag3'
line = log.debug('testline', 'tag1 tag2 tag3')
assert.equal(line, testline)
line = log.debug('testline', 'tag1,tag2,tag3')
assert.equal(line, testline)
line = log.debug('testline', ['tag1', 'tag2', 'tag3'])
assert.equal(line, testline)
})
})
})
describe(': File Set', function () {
beforeEach('create Object', function () {
log = new LOG({
file: file
})
fs.writeFileSync(file, '') // Create File if not exists
})
afterEach('destroy Object', function () {
log = undefined
fs.truncateSync(file) // Clean Up, clear contents
})
describe(': Info', function () {
it('should output the given Line to the file', function (done) {
testline = getDate() + '\t' + hostname + '\tlog\tINFO\ttestline\n'
log.info('testline')
setTimeout(function () {
line = fs.readFileSync(file, 'utf-8')
assert.equal(line, testline)
done()
}, 10)
})
})
describe(': Notice', function () {
it('should output the given Line to the file', function (done) {
testline = getDate() + '\t' + hostname + '\tlog\tNOTICE\ttestline\n'
log.notice('testline')
setTimeout(function () {
line = fs.readFileSync(file, 'utf-8')
assert.equal(line, testline)
done()
}, 10)
})
})
describe(': Warn', function () {
it('should output the given Line to the file', function (done) {
testline = getDate() + '\t' + hostname + '\tlog\tWARN\ttestline\n'
log.warn('testline')
setTimeout(function () {
line = fs.readFileSync(file, 'utf-8')
assert.equal(line, testline)
done()
}, 10)
})
})
describe(': Error', function () {
it('should output the given Line to the file', function (done) {
testline = getDate() + '\t' + hostname + '\tlog\tERROR\ttestline\n'
log.error('testline')
setTimeout(function () {
line = fs.readFileSync(file, 'utf-8')
assert.equal(line, testline)
done()
}, 10)
})
})
describe(': Fatal', function () {
it('should output the given Line to the file', function (done) {
testline = getDate() + '\t' + hostname + '\tlog\tFATAL\ttestline\n'
log.fatal('testline')
setTimeout(function () {
line = fs.readFileSync(file, 'utf-8')
assert.equal(line, testline)
done()
}, 10)
})
})
describe(': Debug', function () {
it('should output the given Line to the file', function (done) {
testline = getDate() + '\t' + hostname + '\tlog\tDEBUG\ttestline\n'
log.debug('testline')
setTimeout(function () {
line = fs.readFileSync(file, 'utf-8')
assert.equal(line, testline)
done()
}, 10)
})
})
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment