New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flaschenpost

Package Overview
Dependencies
Maintainers
4
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flaschenpost - npm Package Compare versions

Comparing version 0.14.2 to 0.15.0

lib/Configuration/parseLogDebugModulesEnvironmentVariable.js

7

lib/Configuration/index.js

@@ -9,3 +9,4 @@ 'use strict';

const defaultLevels = require('../defaultLevels.json'),
parseEnvironmentVariable = require('./parseEnvironmentVariable');
parseLogDebugModulesEnvironmentVariable = require('./parseLogDebugModulesEnvironmentVariable'),
parseLogLevelsEnvironmentVariable = require('./parseLogLevelsEnvironmentVariable');

@@ -15,2 +16,4 @@ const Configuration = function () {

this.setHost(os.hostname());
this.debugModules = parseLogDebugModulesEnvironmentVariable();
};

@@ -35,3 +38,3 @@

let enabledLogLevels = parseEnvironmentVariable();
let enabledLogLevels = parseLogLevelsEnvironmentVariable();

@@ -38,0 +41,0 @@ if (enabledLogLevels.length === 0) {

{
"fatal": {
"color": "blue",
"color": "magenta",
"enabled": true

@@ -5,0 +5,0 @@ },

@@ -10,2 +10,3 @@ 'use strict';

const Configuration = require('./Configuration'),
FormatterCustom = require('./formatters/Custom'),
FormatterGelf = require('./formatters/Gelf'),

@@ -16,2 +17,3 @@ FormatterHumanReadable = require('./formatters/HumanReadable'),

Middleware = require('./Middleware'),
objectFrom = require('./objectFrom'),
readPackageJson = require('./readPackageJson');

@@ -33,14 +35,12 @@

switch (requestedFormatter) {
case 'gelf':
formatter = new FormatterGelf();
break;
case 'human':
formatter = new FormatterHumanReadable();
break;
case 'json':
formatter = new FormatterJson();
break;
default:
throw new Error('Unsupported formatter.');
if (requestedFormatter === 'gelf') {
formatter = new FormatterGelf();
} else if (requestedFormatter === 'human') {
formatter = new FormatterHumanReadable();
} else if (requestedFormatter === 'json') {
formatter = new FormatterJson();
} else if (requestedFormatter.startsWith('js:')) {
formatter = new FormatterCustom({ file: /^js:(.*)$/g.exec(requestedFormatter)[1] });
} else {
throw new Error('Unsupported formatter.');
}

@@ -73,3 +73,3 @@

logger[levelName] = (message, metadata) => {
logger[levelName] = function (message, metadata) {
if (!message) {

@@ -82,2 +82,4 @@ throw new Error('Message is missing.');

metadata = objectFrom(metadata, arguments.length === 2);
letter.write({

@@ -92,3 +94,16 @@ host: this.configuration.host,

});
};
}.bind(this);
const debugToBeWrapped = logger.debug;
logger.debug = function (message, metadata) {
if (
this.configuration.debugModules.length > 0 &&
!this.configuration.debugModules.includes(logger.module.name)
) {
return;
}
debugToBeWrapped(message, metadata);
}.bind(this);
});

@@ -95,0 +110,0 @@

@@ -46,5 +46,3 @@ 'use strict';

result += '\n';
/* eslint-disable max-len */
result += colorize(`${timestamp.format('HH:mm:ss.SSS')}@${timestamp.format('YYYY-MM-DD')} ${chunk.pid}#${chunk.id}`, 'gray');
/* eslint-enable max-len */
result += '\n';

@@ -51,0 +49,0 @@ if (chunk.metadata) {

{
"name": "flaschenpost",
"version": "0.14.2",
"version": "0.15.0",
"description": "flaschenpost is a logger for cloud-based applications.",

@@ -25,2 +25,6 @@ "contributors": [

"email": "joachim.haecker-becker@arcor.de"
},
{
"name": "Stefan Heine",
"email": "stefan.heine@hpe.com"
}

@@ -39,4 +43,4 @@ ],

"find-root": "1.0.0",
"lodash": "4.15.0",
"moment": "2.15.0",
"lodash": "4.16.6",
"moment": "2.15.1",
"processenv": "0.1.0",

@@ -46,8 +50,8 @@ "split2": "2.1.0",

"stringify-object": "2.4.0",
"uuidv4": "0.3.1",
"uuidv4": "0.4.0",
"varname": "2.0.2"
},
"devDependencies": {
"assertthat": "0.8.0",
"async": "2.0.1",
"assertthat": "0.8.1",
"async": "2.1.2",
"express": "4.14.0",

@@ -57,7 +61,7 @@ "knockat": "0.2.1",

"nodeenv": "0.2.1",
"roboter": "0.13.0",
"roboter-server": "0.13.0",
"shelljs": "0.7.4",
"roboter": "0.13.6",
"roboter-server": "0.13.6",
"shelljs": "0.7.5",
"sinon": "1.17.6",
"supertest": "2.0.0"
"supertest": "2.0.1"
},

@@ -64,0 +68,0 @@ "repository": {

@@ -45,13 +45,14 @@ # flaschenpost

If you want to provide additional meta data, use an object as second parameter.
If you want to provide additional meta data, provide them as an object as the second parameter.
```javascript
logger.info('App started.', {
name: 'foo',
bar: {
baz: 23
}
});
logger.info('App started.', { port: 3000 });
```
Please note that you may also use any other arbitrary type, as long as it can be stringified, but because the resulting log message will lack any descriptive keys, it will be less readable and harder to understand. That's why you should favor objects over other data types.
```javascript
logger.info('App started.', 3000);
```
#### Defining the log target

@@ -70,5 +71,29 @@

json | The default json format.
js: | A custom format (see [Using a custom human-readable format](#using-a-custom-human-readable-format)).
*Please note that by providing `human` you can force flaschenpost to always show human-readable output, no matter whether there is a TTY or not.*
##### Using a custom human-readable format
Maybe you want to adjust the styling of the human-readable format. For that, you can provide a custom formatter. Basically, a custom formatter is nothing but a function that gets the log message as an object and returns a formatted string.
Hence, a simple implementation may look like the following code snippet.
```javascript
'use strict';
const format = function (log) {
return `${log.level} ${log.message}`;
};
module.exports = format;
```
To actually use a custom human-readable format, set the environment variable `FLASCHENPOST_FORMATTER` to `js:` and add the absolute path to the file that contains the `format` function. Instead of a file you may also provide the name of a module that provides the `format` function.
```bash
$ export FLASCHENPOST_FORMATTER=js:/foo/bar/myFormatter.js
$ export FLASCHENPOST_FORMATTER=js:myFormatter
```
#### Setting a custom host

@@ -87,3 +112,3 @@

```bash
$ export LOG_LEVELS=debug,info
$ export LOG_LEVELS=fatal,error,warn,info,debug
```

@@ -97,29 +122,8 @@

### Setting custom log levels
### Restricting `debug` logging
If you want to change the default log levels, i.e. define other log levels, change colors or define which log levels are enabled by default, call the `use` function of flaschenpost.
If the log level `debug` is enabled, by default this affects all modules. From time to time it may be desired to restrict debug logging to specific modules. For that, set the `LOG_DEBUG_MODULES` environment variable to a comma-separated list of the modules' names that you want to track.
```javascript
flaschenpost.use('levels', {
fatal: {
color: 'blue',
enabled: true
},
error: {
color: 'red',
enabled: true
},
warn: {
color: 'yellow',
enabled: true
},
info: {
color: 'green',
enabled: true
},
debug: {
color: 'white',
enabled: false
}
});
```bash
$ export LOG_DEBUG_MODULES=module1,@scoped/module2
```

@@ -126,0 +130,0 @@

@@ -114,2 +114,29 @@ 'use strict';

assert.that(paragraph.source).is.equalTo(__filename);
assert.that(paragraph.metadata).is.undefined();
done();
});
logger.info('App started.');
});
test('writes the message to a letter with metadata.', done => {
flaschenpost.use('host', 'example.com');
const logger = flaschenpost.getLogger(__filename);
letter.once('data', paragraph => {
assert.that(paragraph).is.ofType('object');
assert.that(paragraph.host).is.equalTo('example.com');
assert.that(paragraph.pid).is.equalTo(process.pid);
assert.that(paragraph.id).is.ofType('number');
assert.that(paragraph.timestamp).is.not.undefined();
assert.that(paragraph.level).is.equalTo('info');
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({
name: 'foo',
version: '0.0.1'
});
assert.that(paragraph.source).is.equalTo(__filename);
assert.that(paragraph.metadata).is.equalTo({

@@ -124,3 +151,3 @@ foo: 'bar',

logger.info(`App started.`, {
logger.info('App started.', {
foo: 'bar',

@@ -133,2 +160,58 @@ metadata: {

test('writes the message to a letter with metadata other than object.', done => {
flaschenpost.use('host', 'example.com');
const logger = flaschenpost.getLogger(__filename);
letter.once('data', paragraph => {
assert.that(paragraph).is.ofType('object');
assert.that(paragraph.host).is.equalTo('example.com');
assert.that(paragraph.pid).is.equalTo(process.pid);
assert.that(paragraph.id).is.ofType('number');
assert.that(paragraph.timestamp).is.not.undefined();
assert.that(paragraph.level).is.equalTo('info');
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({
name: 'foo',
version: '0.0.1'
});
assert.that(paragraph.source).is.equalTo(__filename);
assert.that(paragraph.metadata).is.equalTo({ value: 3000 });
done();
});
logger.info('App started.', 3000);
});
test('writes the message to a letter with an error as metadata.', done => {
flaschenpost.use('host', 'example.com');
const logger = flaschenpost.getLogger(__filename);
letter.once('data', paragraph => {
assert.that(paragraph).is.ofType('object');
assert.that(paragraph.host).is.equalTo('example.com');
assert.that(paragraph.pid).is.equalTo(process.pid);
assert.that(paragraph.id).is.ofType('number');
assert.that(paragraph.timestamp).is.not.undefined();
assert.that(paragraph.level).is.equalTo('info');
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({
name: 'foo',
version: '0.0.1'
});
assert.that(paragraph.source).is.equalTo(__filename);
assert.that(paragraph.metadata).is.ofType('object');
assert.that(paragraph.metadata.name).is.equalTo('Error');
assert.that(paragraph.metadata.message).is.equalTo('Something went wrong.');
done();
});
logger.info('App started.', new Error('Something went wrong.'));
});
test('writes the message to a letter even when no filename was specified.', done => {

@@ -181,4 +264,101 @@ const logger = flaschenpost.getLogger();

});
suite('debug modules', () => {
test('writes log level debug if debugging is not restricted to specific modules.', done => {
flaschenpost.configuration.levels.debug.enabled = true;
flaschenpost.configuration.debugModules = [];
const logger = flaschenpost.getLogger(__filename);
let counter = 0;
letter.once('data', () => {
counter += 1;
});
logger.debug('App started.');
setTimeout(() => {
assert.that(counter).is.equalTo(1);
done();
}, 0.1 * 1000);
});
test('writes log level debug if debugging is restricted to a single module and the module matches.', done => {
flaschenpost.configuration.levels.debug.enabled = true;
flaschenpost.configuration.debugModules = [ 'foo' ];
const logger = flaschenpost.getLogger(__filename);
let counter = 0;
letter.once('data', () => {
counter += 1;
});
logger.debug('App started.');
setTimeout(() => {
assert.that(counter).is.equalTo(1);
done();
}, 0.1 * 1000);
});
test('does not write log level debug if debugging is restricted to a single module and the module does not match.', done => {
flaschenpost.configuration.levels.debug.enabled = true;
flaschenpost.configuration.debugModules = [ 'bar' ];
const logger = flaschenpost.getLogger(__filename);
let counter = 0;
letter.once('data', () => {
counter += 1;
});
logger.debug('App started.');
setTimeout(() => {
assert.that(counter).is.equalTo(0);
done();
}, 0.1 * 1000);
});
test('writes log level debug if debugging is restricted to multiple modules and the module matches.', done => {
flaschenpost.configuration.levels.debug.enabled = true;
flaschenpost.configuration.debugModules = [ 'foo', 'bar' ];
const logger = flaschenpost.getLogger(__filename);
let counter = 0;
letter.once('data', () => {
counter += 1;
});
logger.debug('App started.');
setTimeout(() => {
assert.that(counter).is.equalTo(1);
done();
}, 0.1 * 1000);
});
test('does not write log level debug if debugging is restricted to multiple modules and the module does not match.', done => {
flaschenpost.configuration.levels.debug.enabled = true;
flaschenpost.configuration.debugModules = [ 'bar', 'baz' ];
const logger = flaschenpost.getLogger(__filename);
let counter = 0;
letter.once('data', () => {
counter += 1;
});
logger.debug('App started.');
setTimeout(() => {
assert.that(counter).is.equalTo(0);
done();
}, 0.1 * 1000);
});
});
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc