Skip to content

Commit

Permalink
Merge 59269d9 into 447844e
Browse files Browse the repository at this point in the history
  • Loading branch information
hidori committed Jul 26, 2020
2 parents 447844e + 59269d9 commit af1c47a
Show file tree
Hide file tree
Showing 11 changed files with 2,919 additions and 5,240 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
*.test.js
13 changes: 13 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,13 @@
module.exports = {
parserOptions: {
ecmaVersion: 2017,
},
env: {
node: true,
},
extends: ['eslint:recommended'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
},
};
24 changes: 0 additions & 24 deletions .eslintrc.json

This file was deleted.

99 changes: 94 additions & 5 deletions .gitignore
Expand Up @@ -4,6 +4,10 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand All @@ -16,11 +20,12 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -29,22 +34,31 @@ bower_components
# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -56,12 +70,48 @@ typings/

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
Expand All @@ -74,11 +124,12 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -97,12 +148,21 @@ jspm_packages/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -114,6 +174,35 @@ typings/

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
1 change: 1 addition & 0 deletions .node-version
@@ -0,0 +1 @@
12.18.2
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
save-exact=true
9 changes: 9 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,9 @@
module.exports = {
tabWidth: 4,
semi: true,
singleQuote: true,
quoteProps: 'consistent',
trailingComma: 'all',
arrowParens: 'always',
printWidth: 192,
};
13 changes: 11 additions & 2 deletions .travis.yml
@@ -1,5 +1,14 @@
language: node_js
node_js:
- "8.15"
- "10.15"
- 8.17.0
- 9.11.2
- 10.22.0
- 11.15.0
- 12.18.2
- 13.14.0
after_success: "./node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls"
notifications:
email: false
slack:
rooms:
secure: EqiJVewhfLpKIXB9RxzGGblWe4yA+W7ORaaWBqYwOt6R6R1Bg0Kd57h+F18CHNSu0IqXaxVB4slnH7+8AnqX/CpGffqSIdX5gMNsJxyXJGK2sNK+kjMQ3su+RIuBWZWxPcGpQ9Xl9/iZf1tVSdTZGnwcPl+rch4VtWqr7AQnVpPH/7f5FR+Hi2U2sjYGQO+YvFk4qqToe0GCTTLHd+2mcyAWMxLAnrJXqUx91PafRZtf7mqIQC0zoAm+mq/1vkKnDIqBREfe1TdJ0vVIG4c4CNDSX0/xbGUSCSDj8ZD9eyg9ila01cM860OCIs1f4f8nGBhTG1KphV2wglHfl/9TbjMXrr9kCT+fObfCcBhryqa4ZrbkHMupLpFCQFRC0afNJFkIBEySLsm+LbWrfTtuYlLRa7ckgnLHJHcQQthfYnzOi1h9D7v6NZBbzqVvVdBT+IPL9PEPcosHujFff6f/a4FlLVcTgu+KMWlK6mbX8/C7BUBw0sFix2xt6wTBSUG2VFI9c0uDSgMg3KubUwNbWVQqa39jwTN8kKG3hIqj3dFzmC1q9UQncMrSepEG86IHHdV2NfnQdWYeKsXeTPgHbIlXzL8WrzNyudFY7fCNcIcihLKZW4RlBVqb2tqXCFp9Py9wqpml/JAJV5UDF9stpUMo5fT2FrbtBjBq7K/1bOs=
43 changes: 31 additions & 12 deletions README.md
Expand Up @@ -3,16 +3,18 @@
[![Build Status](https://travis-ci.org/hidori/node-json-logger.svg)](https://travis-ci.org/hidori/node-json-logger)
[![Coverage Status](https://coveralls.io/repos/github/hidori/node-json-logger/badge.svg)](https://coveralls.io/github/hidori/node-json-logger)

node-json-logger
----
# node-json-logger

Simply, output logs to STDOUT in JSON

# Install
## Install

```sh
npm i node-json-logger
```

# Usage
## Usage

```js
const Logger = require('node-json-logger');
const logger = new Logger();
Expand All @@ -26,6 +28,7 @@ logger.info('message', { data1: 'data' }, 'message', { data2: 'data' }, 'message
```

Outputs:

```json
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","message":"message"}
Expand All @@ -35,29 +38,35 @@ Outputs:
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","message":"message","data1":"data","message1":"message","data2":"data","message2":"message"}
```

# API
## API

```js
logger.xxx(message?, ...)
```
Note:
* xxx is one of the [Levels](#Levels)
Arguments:
* message: Specify a message as string or object.
# <a href="#Levels"></a>Levels
## <a href="#Levels"></a>Levels
* trace
* debug
* info
* warn
* error
* fatal
# Configuration
## Configuration
### level
## level
Specify output level. (optional, default is `debug`)
```js
const Logger = require('node-json-logger');
const logger = new Logger({ level: 'error'});
Expand All @@ -71,6 +80,7 @@ logger.fatal('message');
```
Output:
```json
{"timestamp":"2001-03-14T01:00:00.000Z","level":"error","message":"message"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"fatal","message":"message"}
Expand All @@ -88,8 +98,10 @@ Level and output:
| `{ level: 'fatal' }` | - | - | - | - | - | O |
| `{ level: 'none' }` | - | - | - | - | - | - |
## loggerName
### loggerName
Specify the name of the logger. Useful when logging from different files.
```js
const Logger = require('node-json-logger');
const logger = new Logger({ loggerName: 'server/index.js' });
Expand All @@ -98,11 +110,13 @@ logger.info('message');
```
Output:
```json
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","loggerName":"server/index.js","message":"message"}
```
## timestamp
### timestamp
Specify enable or disable timestamp. (optional, default is true)
```js
Expand All @@ -113,11 +127,13 @@ logger.info('message');
```
Output with disabled timestamp:
```json
{"level":"info","message":"message"}
```
## timezone
### timezone
Specify locale timezone. (optional, default is UTC)
```js
Expand All @@ -128,18 +144,21 @@ logger.info('message');
```
Output with specific timezone:
```json
{"timestamp":"2018-10-25T15:32:43.318Z","level":"info","message":"message"}
```
Same output with default timezone (UTC):
```json
{"timestamp":"2018-10-25T18:32:43.318Z","level":"info","message":"message"}
```
[Click here](https://momentjs.com/timezone/) to see the list with all available timezones.
# License
## License
MIT
Copyright &copy;2018 Hiroaki SHIBUKI a.k.a. [hidori](https://github.com/hidori)

0 comments on commit af1c47a

Please sign in to comment.