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

ecs-logs-js

Package Overview
Dependencies
Maintainers
150
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ecs-logs-js - npm Package Compare versions

Comparing version 0.2.3 to 1.0.0

dist/src/index.d.ts

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`.
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