flaschenpost
Advanced tools
Comparing version 0.12.1 to 0.13.0
'use strict'; | ||
const path = require('path'); | ||
const _ = require('lodash'), | ||
appRootPath = require('app-root-path'), | ||
findRoot = require('find-root'), | ||
@@ -17,3 +16,4 @@ processenv = require('processenv'), | ||
Middleware = require('./Middleware'), | ||
Paragraph = require('./letter/Paragraph'); | ||
Paragraph = require('./letter/Paragraph'), | ||
readPackageJson = require('./readPackageJson'); | ||
@@ -24,2 +24,3 @@ const flaschenpost = {}; | ||
this.configuration = new Configuration(); | ||
this.configuration.application = readPackageJson(appRootPath.path); | ||
@@ -60,17 +61,6 @@ letter.unpipe(); | ||
try { | ||
/* eslint-disable global-require */ | ||
const packageJson = require(path.join(findRoot(source), 'package.json')); | ||
/* eslint-enable global-require */ | ||
const logger = {}; | ||
this.configuration.module = { | ||
name: packageJson.name, | ||
version: packageJson.version | ||
}; | ||
} catch (ex) { | ||
throw new Error('Could not find package.json.'); | ||
} | ||
logger.module = readPackageJson(findRoot(source)); | ||
const logger = {}; | ||
_.forOwn(this.configuration.levels, (levelOptions, levelName) => { | ||
@@ -95,3 +85,4 @@ if (!levelOptions.enabled) { | ||
host: this.configuration.host, | ||
module: this.configuration.module, | ||
application: this.configuration.application, | ||
module: logger.module, | ||
source, | ||
@@ -125,2 +116,3 @@ level: levelName, | ||
host: 'n/a', | ||
application: { name: 'n/a', version: 'n/a' }, | ||
module: { name: 'n/a', version: 'n/a' }, | ||
@@ -127,0 +119,0 @@ level: 'info', |
@@ -26,11 +26,22 @@ 'use strict'; | ||
const timestamp = moment.utc(chunk.timestamp); | ||
let result = ''; | ||
let origin = '', | ||
result = ''; | ||
result += colorize(`${chunk.message} (${chunk.level})`, 'bold'); | ||
result += '\n'; | ||
result += colorize(`${chunk.host}::${chunk.module.name}@${chunk.module.version}`, 'white'); | ||
origin = `${chunk.host}`; | ||
if (chunk.application) { | ||
// Be backward compatible and allow to parse logs without application data | ||
origin += `::${chunk.application.name}@${chunk.application.version}`; | ||
} | ||
if (!chunk.application || chunk.application.name !== chunk.module.name) { | ||
// Do not print the same module information twice | ||
origin += `::${chunk.module.name}@${chunk.module.version}`; | ||
} | ||
if (chunk.source) { | ||
result += colorize(` (${chunk.source})`, 'white'); | ||
origin += ` (${chunk.source})`; | ||
} | ||
result += colorize(`${chunk.message} (${chunk.level})`, 'bold'); | ||
result += '\n'; | ||
result += colorize(origin, 'white'); | ||
result += '\n'; | ||
/* eslint-disable max-len */ | ||
@@ -37,0 +48,0 @@ result += colorize(`${timestamp.format('HH:mm:ss.SSS')}@${timestamp.format('YYYY-MM-DD')} ${chunk.pid}#${chunk.id}`, 'gray'); |
@@ -32,2 +32,5 @@ 'use strict'; | ||
if (data.application) { | ||
this.application = data.application; | ||
} | ||
if (data.module) { | ||
@@ -34,0 +37,0 @@ this.module = data.module; |
{ | ||
"name": "flaschenpost", | ||
"version": "0.12.1", | ||
"version": "0.13.0", | ||
"description": "flaschenpost is a logger for cloud-based applications.", | ||
@@ -26,20 +26,20 @@ "contributors": [ | ||
"dependencies": { | ||
"app-root-path": "1.3.0", | ||
"chalk": "1.1.3", | ||
"find-root": "1.0.0", | ||
"lodash": "4.13.1", | ||
"moment": "2.13.0", | ||
"moment": "2.14.1", | ||
"processenv": "0.1.0", | ||
"split2": "2.1.0", | ||
"stack-trace": "0.0.9", | ||
"stringify-object": "2.3.1", | ||
"update-notifier": "0.7.0", | ||
"stringify-object": "2.4.0", | ||
"update-notifier": "1.0.2", | ||
"varname": "2.0.2" | ||
}, | ||
"devDependencies": { | ||
"assertthat": "0.7.0", | ||
"express": "4.13.4", | ||
"gulp": "3.9.1", | ||
"assertthat": "0.8.0", | ||
"express": "4.14.0", | ||
"morgan": "1.7.0", | ||
"nodeenv": "0.2.1", | ||
"roboter": "0.6.4", | ||
"roboter": "0.11.9", | ||
"sinon": "1.17.4", | ||
@@ -46,0 +46,0 @@ "supertest": "1.2.0" |
@@ -15,3 +15,8 @@ 'use strict'; | ||
}); | ||
task('universal/coverage', { | ||
src: 'lib/**/*.js', | ||
test: 'test/**/*Tests.js' | ||
}); | ||
}). | ||
start(); |
@@ -23,11 +23,2 @@ 'use strict'; | ||
suite('module', () => { | ||
test('does not exist by default.', done => { | ||
const configuration = new Configuration(); | ||
assert.that(configuration.module).is.undefined(); | ||
done(); | ||
}); | ||
}); | ||
suite('levels', () => { | ||
@@ -34,0 +25,0 @@ test('is an object.', done => { |
@@ -113,2 +113,4 @@ 'use strict'; | ||
assert.that(paragraph.message).is.equalTo('App started.'); | ||
assert.that(paragraph.application.name).is.equalTo('flaschenpost'); | ||
assert.that(paragraph.application.version).is.not.undefined(); | ||
assert.that(paragraph.module).is.equalTo({ | ||
@@ -193,2 +195,6 @@ name: 'foo', | ||
host: 'example.com', | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -211,3 +217,3 @@ name: 'foo', | ||
'App started. (info)', | ||
'example.com::foo@0.0.1 (' | ||
'example.com::app@1.2.3::foo@0.0.1 (' | ||
].join('\n'))).is.equalTo(0); | ||
@@ -236,2 +242,6 @@ | ||
host: 'example.com', | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -254,3 +264,3 @@ name: 'foo', | ||
'App started. (info)', | ||
'example.com::foo@0.0.1 (' | ||
'example.com::app@1.2.3::foo@0.0.1 (' | ||
].join('\n'))).is.equalTo(0); | ||
@@ -278,2 +288,6 @@ | ||
host: 'example.com', | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -280,0 +294,0 @@ name: 'foo', |
@@ -33,2 +33,6 @@ 'use strict'; | ||
message: 'App started.', | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -48,2 +52,39 @@ name: 'foo', | ||
'App started. (info)', | ||
'example.com::app@1.2.3::foo@0.0.1 (app.js)', | ||
'14:28:59.974@2014-11-03 82517#0', | ||
'{', | ||
' foo: \'bar\'', | ||
'}', | ||
'\u2500'.repeat(process.stdout.columns || 80), | ||
'' | ||
/* eslint-enable nodeca/indent */ | ||
].join('\n')); | ||
done(); | ||
}); | ||
humanReadable.write(paragraph); | ||
}); | ||
test('does not throw an error if application information is missing.', done => { | ||
const paragraph = { | ||
host: 'example.com', | ||
pid: 82517, | ||
id: 0, | ||
timestamp: 1415024939974, | ||
level: 'info', | ||
message: 'App started.', | ||
module: { | ||
name: 'foo', | ||
version: '0.0.1' | ||
}, | ||
source: 'app.js', | ||
metadata: { | ||
foo: 'bar' | ||
} | ||
}; | ||
humanReadable.once('data', data => { | ||
assert.that(chalk.stripColor(data)).is.equalTo([ | ||
/* eslint-disable nodeca/indent */ | ||
'App started. (info)', | ||
'example.com::foo@0.0.1 (app.js)', | ||
@@ -63,2 +104,43 @@ '14:28:59.974@2014-11-03 82517#0', | ||
}); | ||
test('does not print information twice if application and module are the same.', done => { | ||
const paragraph = { | ||
host: 'example.com', | ||
pid: 82517, | ||
id: 0, | ||
timestamp: 1415024939974, | ||
level: 'info', | ||
message: 'App started.', | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
source: 'app.js', | ||
metadata: { | ||
foo: 'bar' | ||
} | ||
}; | ||
humanReadable.once('data', data => { | ||
assert.that(chalk.stripColor(data)).is.equalTo([ | ||
/* eslint-disable nodeca/indent */ | ||
'App started. (info)', | ||
'example.com::app@1.2.3 (app.js)', | ||
'14:28:59.974@2014-11-03 82517#0', | ||
'{', | ||
' foo: \'bar\'', | ||
'}', | ||
'\u2500'.repeat(process.stdout.columns || 80), | ||
'' | ||
/* eslint-enable nodeca/indent */ | ||
].join('\n')); | ||
done(); | ||
}); | ||
humanReadable.write(paragraph); | ||
}); | ||
}); |
@@ -31,2 +31,6 @@ 'use strict'; | ||
message: 'App started.', | ||
process: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -52,2 +56,6 @@ name: 'foo', | ||
'"message":"App started.",', | ||
'"process":{', | ||
'"name":"app",', | ||
'"version":"1.2.3"', | ||
'},', | ||
'"module":{', | ||
@@ -54,0 +62,0 @@ '"name":"foo",', |
@@ -23,2 +23,6 @@ 'use strict'; | ||
message: 'App started.', | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -38,2 +42,3 @@ name: 'foo', | ||
assert.that(paragraph.message).is.equalTo(expected.message); | ||
assert.that(paragraph.application).is.equalTo(expected.application); | ||
assert.that(paragraph.module).is.equalTo(expected.module); | ||
@@ -54,2 +59,6 @@ assert.that(paragraph.source).is.undefined(); | ||
source: __filename, | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -77,2 +86,6 @@ name: 'foo', | ||
}, | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -101,2 +114,6 @@ name: 'foo', | ||
}, | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -125,2 +142,6 @@ name: 'foo', | ||
message: 'App started.', | ||
application: { | ||
name: 'app', | ||
version: '1.2.3' | ||
}, | ||
module: { | ||
@@ -127,0 +148,0 @@ name: 'foo', |
@@ -86,2 +86,17 @@ 'use strict'; | ||
test('returns a paragraph with a process if a process is given.', done => { | ||
const id = 23; | ||
const data = { | ||
host: 'example.com', | ||
level: 'error', | ||
message: 'foo', | ||
process: 'bar' | ||
}; | ||
const paragraph = new Paragraph(id, data); | ||
assert.that(paragraph.application).is.equalTo(data.application); | ||
done(); | ||
}); | ||
test('returns a paragraph with a module if a module is given.', done => { | ||
@@ -88,0 +103,0 @@ const id = 23; |
@@ -55,2 +55,4 @@ 'use strict'; | ||
assert.that(data.message).is.equalTo('foobar'); | ||
assert.that(data.application.name).is.equalTo('flaschenpost'); | ||
assert.that(data.application.version).is.not.undefined(); | ||
assert.that(data.module).is.equalTo({ | ||
@@ -57,0 +59,0 @@ name: 'foo', |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
137720
7
33
1662
11
+ Addedapp-root-path@1.3.0
+ Addedapp-root-path@1.3.0(transitive)
+ Addedboxen@0.6.0(transitive)
+ Addedlazy-req@1.1.0(transitive)
+ Addedmoment@2.14.1(transitive)
+ Addedstringify-object@2.4.0(transitive)
+ Addedupdate-notifier@1.0.2(transitive)
- Removedboxen@0.5.1(transitive)
- Removedmoment@2.13.0(transitive)
- Removedstringify-object@2.3.1(transitive)
- Removedupdate-notifier@0.7.0(transitive)
Updatedmoment@2.14.1
Updatedstringify-object@2.4.0
Updatedupdate-notifier@1.0.2