Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@5app/logger

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@5app/logger - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

levels.js

4

.eslintrc.json

@@ -8,2 +8,5 @@ {

],
"env": {
"mocha": true
},
"rules": {

@@ -16,2 +19,3 @@ "array-bracket-newline": [2, "consistent"],

"dot-location": [2, "property"],
"no-console": 0,
"no-empty-function": 2,

@@ -18,0 +22,0 @@ "no-magic-numbers": 0,

@@ -0,1 +1,13 @@

# [2.0.0](https://github.com/5app/logger/compare/v1.1.0...v2.0.0) (2019-09-12)
### Features
* Drop winston and simpplify the logger ([fa86131](https://github.com/5app/logger/commit/fa86131))
### BREAKING CHANGES
* The logger do not allow using winston's API anymore as we dropped winston
# [1.1.0](https://github.com/5app/logger/compare/v1.0.2...v1.1.0) (2019-09-12)

@@ -2,0 +14,0 @@

32

index.js

@@ -1,20 +0,20 @@

const getLogger = require('./getLogger');
const simple = require('./outputs/simple');
const json = require('./outputs/json');
const levels = require('./levels');
const priority = require('./priority');
const {
LOGS_FORMAT,
LOGS_LEVEL,
TAG
} = process.env;
const {LOGS_FORMAT, LOGS_LEVEL} = process.env;
const logger = getLogger({
simple: LOGS_FORMAT !== 'json',
level: LOGS_LEVEL || 'debug',
metadata: {
tag: TAG
}
const logger = LOGS_FORMAT === 'json' ? json : simple;
const minimumPriority = priority(LOGS_LEVEL || 'debug');
// eslint-disable-next-line no-empty-function
const noLog = () => {};
const methods = {};
Object.keys(levels).forEach(level => {
methods[level] = priority(level) >= minimumPriority ? (message, context) => logger(level, message, context) : noLog;
});
module.exports = {
logger,
getLogger
};
module.exports = methods;
{
"name": "@5app/logger",
"version": "1.1.0",
"version": "2.0.0",
"description": "Logger used in 5app microservices",

@@ -12,3 +12,3 @@ "main": "index.js",

"precommit-msg": "echo 'Running pre-commit checks... (skip using --no-verify)' && exit 0",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},

@@ -40,2 +40,3 @@ "pre-commit": [

"eslint-plugin-security": "^1.4.0",
"mocha": "^6.2.0",
"pre-commit": "^1.2.2",

@@ -67,3 +68,3 @@ "semantic-release": "^15.13.24"

"dependencies": {
"winston": "^3.2.1"
"chalk": "^2.4.2"
},

@@ -70,0 +71,0 @@ "publishConfig": {

@@ -10,6 +10,4 @@ # logger

Then, generate a logger in your app and use it to log messages.
```javascript
const {logger} = require('@5app/logger');
const logger = require('@5app/logger');

@@ -24,77 +22,21 @@ logger.info('An email was sent', {

Alternatively, you can create a new instance of logger where you can specify the metadata, logging level, and whether you want simple logs or not:
```javascript
const {getLogger} = require('@5app/logger');
const logger = getLogger({
simple: process.env.NODE_ENV === 'development',
metadata: {
tag: process.env.TAG, // release tag, e.g. docker container tag
},
});
logger.info('An email was sent', {
email: 'customer@5app.com',
template: 'template1',
});
logger.error(new Error('Unknown playlist 123'));
```
## Options
The logger generator accepts the following options:
The logger can optionally be customised using the following environment variables:
### simple
- `LOGS_FORMAT`: if set to `json`, the logger will log messages in json format instead of pretty messages (default behaviour).
- `LOGS_LEVEL`: minimum logging level, by default it will be `debug`. Accepted values are `'debug'`, `'info'`, `'warn'`, and `'error'`
- `TAG`: release tag (e.g. docker image tag) to be added to the log messages
This boolean value specifies whether we should log pretty dev-friendly messages instead of JSON or not.
By default, simple will be false.
## Logging levels
Example:
```javascript
const {getLogger} = require('@5app/logger');
Logging levels are (from lower to higher priority): `'debug'`, `'info'`, `'warn'`, and `'error'`.
The logger provides the logging functions with the following signatures: `logger.<level>(message, objectOrError)`
// This logger will log dev-friendly messages
const logger = getLogger({
simple: true,
});
Here is an example of how the logger can be used:
```
The default logger uses the environment variable `LOGS_FORMAT` to determine if the logs are going to be generated in json (`json`) or simple console logs (any other value other than `json`).
### metadata
Metadata is an object containing service metadata like the release tag or the A/B testing experiment we are running.
This object will be added to each log entry when using the JSON mode.
Example:
```javascript
const {getLogger} = require('@5app/logger');
// This logger will add details about the current release and A/B experiment to every log line
const logger = getLogger({
metadata: {
release: '1.2.3',
experiment: 12345,
},
});
logger.error('An error happened', new ApiError('The api call failed', 404)); // will log the message, the error message, the stack trace, and the statusCode error property
logger.warn('Be warned', {a: 1, b: Date.now(), c: 'some string'});
logger.info('An event happened', {a: 1, b: Date.now(), c: 'some string'});
logger.debug('A minor operation', {a: 1, b: Date.now(), c: 'some string'});
```
### level
You can specify a minimum logging level using the `level` parameter or using the `LOGS_LEVEL` environment variable.
By default, the logging level will be [debug (npm)](https://github.com/winstonjs/winston#logging-levels).
Example:
```javascript
const {getLogger} = require('@5app/logger');
// This logger will add details about the current release and A/B experiment to every log line
const logger = getLogger({
level: 'warn',
});
logger.info('this message will not be logged');
logger.warn('you will see this message');
```

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