# js-standard-logger

> A useful standard Logger for JS

Latest version **1.0.30** (published 2019-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-standard-logger
pnpm add js-standard-logger
yarn add js-standard-logger
bun add js-standard-logger
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.30 |
| Published | 2019-03-27 |
| First published | 2018-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | roren15 |
| Maintainers | roren |
| Keywords | log, logger, logging, logs, loglevel, tools, timestamp, save, standard, pretty, format, output, useful winston, stringify |

## Links

- npm: https://www.npmjs.com/package/js-standard-logger
- Repository: https://github.com/roren15/js-standard-logger
- Issues: https://github.com/roren15/js-standard-logger/issues
- npm.io page: https://npm.io/package/js-standard-logger

## Dependencies (3)

- [winston](https://npm.io/package/winston.md) ^3.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.0
- [circular-json](https://npm.io/package/circular-json.md) ^0.5.9

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.30 (latest) — 2019-03-27
- 1.0.29 — 2019-03-27
- 1.0.28 — 2019-03-27
- 1.0.27 — 2019-03-26
- 1.0.26 — 2019-03-06
- 1.0.25 — 2019-03-04
- 1.0.24 — 2019-01-29
- 1.0.23 — 2019-01-24
- 1.0.22 — 2019-01-22
- 1.0.21 — 2019-01-22
- 1.0.20 — 2019-01-22
- 1.0.19 — 2018-12-26
- 1.0.18 — 2018-12-24
- 1.0.17 — 2018-12-24
- 1.0.16 — 2018-12-20
- … 16 more at https://npm.io/package/js-standard-logger/versions

## README

# js-standard-logger

A useful standard Logger for JS, based on winston, formatting simple output for log, saving to demanded path.
Common output as: ` [2018-12-11 09:41:19] [info] [sample-label] --- it s info `

[![npm install js-standard-logger](https://nodei.co/npm/js-standard-logger.png?mini=true)](https://www.npmjs.com/package/js-standard-logger)

## 1. Install

```bash
$ npm install --save js-standard-logger
```

## 2. Usage

```javascript
const Logger = require('js-standard-logger')
const logger = new Logger('/data/logs/logger-sample/') // simply initialize


logger.exec('it s info') // default for info level output
//[2018-12-11 09:41:19] [info] [sample-label] --- it s info

logger.exec(`${Logger.stringify({it:'can be object',also:['can','be','array']}, true)}`,Logger.WARN()) // choose diff level
//[2019-03-27 14:20:55] [warn] [test] --- {
//  "it": "can be object",
//  "also": [
//    "can",
//     ...
//  ]
//}

logger.exceptionThrows('log and throw err') // do log and throw err, which required try-catch
//[2018-12-11 09:41:19] [error] [sample-label] --- log and throw err

logger.exec('it s error', Logger.ERROR(), new TypeError('get type error')) // log err stack
//[2019-01-29 09:29:43] [error] [test] --- it s error . err stack : TypeError: get type error
//    at Object.<anonymous> (/home/roren/Documents/source/self/logger/test.js:9:45)
//    at Module._compile (internal/modules/cjs/loader.js:686:14)
//    ...
```

## 3. Api

### Init

Please fill with absolute path.

```javascript
const Logger = require('js-standard-logger')
const logger = new Logger('/data/logs/log-save-dir/', 'log-name.log','default-label', Logger.INFO()) 
```

|arguments|required|description|
|:------:|:------:|------|
|log_save_dir|true|dir abstract path to save log (auto mkdir if not exists)|
|log_name|false|default to "app.log"|
|label|false|label to differ log, default to log_name|
|view_level|false|choose viewing output level, using Logger fields, default to debug|

### Function

#### logger.exec()

Do log on message with different level

|arguments|required|description|
|:------:|:------:|------|
|message|true|message to log|
|level|false|tag the label according to level field, default to info|
|err|false|Error instance, will logged stack|

#### logger.exceptionThrows()

Do log on message and throw error, which recommended to catch outside

|arguments|required|description|
|:------:|:------:|------|
|message|true|message to log|
|level|false|tag the label according to level field, default to error|

#### Logger.inspect()

inspect object to view

|arguments|required|description|
|:------:|:------:|------|
|object|true|inspect object|

#### Logger.stringify()

Transform object to string when logging

|arguments|required|description|
|:------:|:------:|------|
|object|true|stringify object type to do log|
|pretty|false|pretty json output, default false|

### Field

Different level fields to choose

| Fields | Level | Description |
|:------:|:------:|------|
| Logger.DEBUG() | debug | tags for development debug |
| Logger.INFO() | information | tags for information |
| Logger.WARN() | warning | tags for that be bad for some features |
| Logger.ERROR() | error | tags for that intercept process or functional crash |

---
_Source: https://npm.io/package/js-standard-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
