ecs-logs-js
Advanced tools
Comparing version 0.2.3 to 1.0.0
107
package.json
{ | ||
"name": "ecs-logs-js", | ||
"version": "0.2.3", | ||
"description": "Logger based on winston formatting messages compatible with ecs-logs", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "github.com/segmentio/ecs-logs-js" | ||
}, | ||
"version": "1.0.0", | ||
"description": "Simple Node.js console logger that outputs human friendly and ecs-logs compatible messages", | ||
"author": "Roland Warmerdam (https://roland.codes)", | ||
"keywords": [ | ||
"ecs-logs", | ||
"ecs-logs-js", | ||
"log", | ||
@@ -24,14 +15,92 @@ "logger", | ||
], | ||
"author": "Achille Roussel", | ||
"repository": "segmentio/ecs-logs-js", | ||
"license": "MIT", | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"files": [ | ||
"dist/src", | ||
"src" | ||
], | ||
"scripts": { | ||
"prepublishOnly": "yarn clean && yarn build", | ||
"test": "FORCE_COLOR=1 jest", | ||
"lint": "eslint '**/*.ts'", | ||
"build": "tsc", | ||
"clean": "rimraf dist" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"dependencies": { | ||
"json-stringify-safe": "^5.0.1", | ||
"type-name": "^2.0.1", | ||
"winston": "^2.2.0" | ||
"chalk": "^3.0.0", | ||
"extract-stack": "^2.0.0", | ||
"fast-safe-stringify": "^2.0.7", | ||
"js-yaml": "^3.13.1", | ||
"replace-string": "^3.0.0", | ||
"serialize-error": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.0.0", | ||
"eslint-config-google": "^0.6.0", | ||
"mocha": "^2.5.3" | ||
"@types/jest": "^25.1.4", | ||
"@types/js-yaml": "^3.12.3", | ||
"@types/node": "^10", | ||
"@typescript-eslint/eslint-plugin": "^2.3.1", | ||
"@typescript-eslint/parser": "^2.3.1", | ||
"eslint": "^6.4.0", | ||
"eslint-config-prettier": "^6.3.0", | ||
"husky": "^4.2.3", | ||
"jest": "^25.2.3", | ||
"jest-date-mock": "^1.0.8", | ||
"lint-staged": "^10.0.9", | ||
"prettier": "^2.0.2", | ||
"rimraf": "^3.0.0", | ||
"ts-jest": "^25.2.1", | ||
"typescript": "^3.6.3" | ||
}, | ||
"eslintIgnore": [ | ||
"/dist/" | ||
], | ||
"eslintConfig": { | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"prettier", | ||
"prettier/@typescript-eslint" | ||
], | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"env": { | ||
"node": true, | ||
"jest": true | ||
} | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 120 | ||
}, | ||
"jest": { | ||
"preset": "ts-jest", | ||
"testEnvironment": "node", | ||
"clearMocks": true, | ||
"testPathIgnorePatterns": [ | ||
"<rootDir>/dist/" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.ts": [ | ||
"eslint --fix", | ||
"prettier --write" | ||
], | ||
"*.{yml,md,json}": [ | ||
"prettier --write" | ||
] | ||
} | ||
} |
159
README.md
@@ -1,81 +0,112 @@ | ||
# ecs-logs-js [![CircleCI](https://circleci.com/gh/segmentio/ecs-logs-js.svg?style=shield)](https://circleci.com/gh/segmentio/ecs-logs-js) | ||
**Basic usage** | ||
```js | ||
var log = require('ecs-logs-js'); | ||
# ecs-logs-js | ||
log.debug('debug message, not logged if NODE_ENV=production'); | ||
log.info('Hi there!'); | ||
``` | ||
A simple Node.js console logger that outputs human friendly messages in development and [ecs-logs](https://github.com/segmentio/ecs-logs) compatible messages in production. Supports all object types, including those that can't be JSON stringified like Error, Map, Set and BigInt. | ||
## Logger | ||
The Logger type is a winston logger with preconfigured defaults to output | ||
log messages compatible with ecs-logs. | ||
TypeScript types are also included in the package. | ||
**Creating and using a Logger** | ||
```js | ||
var ecslogs = require('ecs-logs-js'); | ||
<img src="./example.png" alt="Development log output example" width="713" /> | ||
var log = new ecslogs.Logger({ | ||
level: 'info' | ||
}); | ||
## Install | ||
log.info('Hi there!'); | ||
```shell | ||
yarn add ecs-logs-js | ||
# or | ||
npm install ecs-logs-js | ||
``` | ||
## Transport | ||
The Transport type implements a winston log transport preconfigured to | ||
output log messages compatible with ecs-logs. | ||
## Usage | ||
**Creating and using a Transport in a winston logger** | ||
```js | ||
var ecslogs = require('ecs-logs-js'); | ||
var winston = require('winston'); | ||
import { Logger } from 'ecs-logs-js' | ||
// Instantiate an ecs-logs compatible winston logger with ecslogs.Transport | ||
var logger = new winston.Logger({ | ||
transports: [ | ||
new ecslogs.Transport() | ||
] | ||
}); | ||
const logger = new Logger({ devMode: true }) | ||
logger.info('Server started at http://localhost:8000') | ||
logger.warn('Request rate limited', { ip: '127.0.0.1' }) | ||
logger.error('🚨 Unexpected Error', new Error('Failed to connect to Postgress')) | ||
``` | ||
## Formatter | ||
The Formatter type implements a winston log formatter that produces messages | ||
compatible with ecs-logs. | ||
## API | ||
The object returned when instantiating the Formatter type is callable. When | ||
called, it expects a log entry object. | ||
### new Logger(options?) | ||
When a formatter instance is called it accepts a log entry as argument and | ||
returns a JSON representation of the entry in a format compatible with | ||
ecs-logs. | ||
Creates a new logger instance. | ||
**Creating and using a Formatter in a winston logger** | ||
```js | ||
var ecslogs = require('ecs-logs-js'); | ||
var winston = require('winston'); | ||
#### options | ||
// Instantiate an ecs-logs compatible winston logger with ecslogs.Formatter | ||
var logger = new winston.Logger({ | ||
transports: [ | ||
new winston.transports.Console({ | ||
timestamp: Date.now, | ||
formatter: new ecslogs.Formatter() | ||
}) | ||
] | ||
}); | ||
``` | ||
**Using a Formatter to serialize log entries** | ||
```js | ||
var ecslogs = require('ecs-logs-js'); | ||
var formatter = new ecslogs.Formatter(); | ||
Type: `object` | ||
// Returns a serialized log message compatible with ecs-logs. | ||
var s = formatter({ | ||
message: 'the log message', | ||
level: 'info', | ||
meta: { | ||
'User-Agent': 'node' | ||
} | ||
}); | ||
``` | ||
##### level | ||
Type: `'emerg' | 'alert' | 'crit' | 'error' | 'warn' | 'notice' | 'info' | 'debug'`<br /> | ||
Default: `'debug'` | ||
Sets the maximum log level that will be output. By setting this option to 'info', it can be used to disable debug logs in production. | ||
##### devMode | ||
Type: `boolean`<br /> | ||
Default: `process.env.NODE_ENV === 'development'` | ||
Enables the human friendly development output. | ||
### logger.log(level, message, data?) | ||
Logs a message at the given log level. | ||
#### level | ||
Type: `'emerg' | 'alert' | 'crit' | 'error' | 'warn' | 'notice' | 'info' | 'debug'` | ||
Log level for the message. | ||
#### message | ||
Type: `string` | ||
The message to log. | ||
#### data | ||
Type: `any` | ||
Any additional data to log with the message. This can be any type. | ||
### logger.emerg(message, data?) | ||
### logger.alert(message, data?) | ||
### logger.crit(message, data?) | ||
### logger.error(message, data?) | ||
### logger.warn(message, data?) | ||
### logger.notice(message, data?) | ||
### logger.info(message, data?) | ||
### logger.debug(message, data?) | ||
Logs a message at the respective log level. | ||
#### message | ||
Type: `string` | ||
The message to log. | ||
#### data | ||
Type: `any` | ||
Any additional data to log with the message. This can be any type. | ||
## Development | ||
Make sure you have [Node >=10](https://nodejs.org) and [Yarn](https://classic.yarnpkg.com/en/docs/install) installed, and then run `yarn install` to install the development dependencies. | ||
To run the tests use `yarn test`. To run the tests in watch mode use `yarn test --watch`. | ||
To lint the files use `yarn lint`. | ||
To compile the TypeScript files use `yarn build`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
25976
1
113
6
15
7
447
3
+ Addedchalk@^3.0.0
+ Addedextract-stack@^2.0.0
+ Addedfast-safe-stringify@^2.0.7
+ Addedjs-yaml@^3.13.1
+ Addedreplace-string@^3.0.0
+ Addedserialize-error@^6.0.0
+ Addedansi-styles@4.3.0(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedchalk@3.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedextract-stack@2.0.0(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedreplace-string@3.1.0(transitive)
+ Addedserialize-error@6.0.0(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtype-fest@0.12.0(transitive)
- Removedjson-stringify-safe@^5.0.1
- Removedtype-name@^2.0.1
- Removedwinston@^2.2.0
- Removedasync@2.6.4(transitive)
- Removedcolors@1.0.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedeyes@0.1.8(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removedstack-trace@0.0.10(transitive)
- Removedtype-name@2.0.2(transitive)
- Removedwinston@2.4.7(transitive)