# easylog

> Sensible winston setup

Latest version **0.1.1** (published 2016-11-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install easylog
pnpm add easylog
yarn add easylog
bun add easylog
```

Provides the command `easylog-schema`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2016-11-03 |
| First published | 2016-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kba |
| Maintainers | kba |
| Keywords | winston |

## Links

- npm: https://www.npmjs.com/package/easylog
- Repository: https://github.com/kba/easylog
- Homepage: https://github.com/kba/easylog#readme
- Issues: https://github.com/kba/easylog/issues
- npm.io page: https://npm.io/package/easylog

## Dependencies (11)

- [tv4](https://npm.io/package/tv4.md) ^1.2.7
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [find-up](https://npm.io/package/find-up.md) ^2.0.0
- [winston](https://npm.io/package/winston.md) ^2.1.1
- [chokidar](https://npm.io/package/chokidar.md) ^1.4.2
- [traverse](https://npm.io/package/traverse.md) ^0.6.6
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [deepmerge](https://npm.io/package/deepmerge.md) ^1.2.0
- [log-pattern](https://npm.io/package/log-pattern.md) 0.0.9
- [read-pkg-up](https://npm.io/package/read-pkg-up.md) ^2.0.0
- [winston-timer](https://npm.io/package/winston-timer.md) 0.0.2

## 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

- 0.1.1 (latest) — 2016-11-03
- 0.1.0 — 2016-11-03
- 0.0.12 — 2016-07-18
- 0.0.11 — 2016-05-04
- 0.0.10 — 2016-01-28
- 0.0.9 — 2016-01-27
- 0.0.8 — 2016-01-27
- 0.0.7 — 2016-01-27
- 0.0.6 — 2016-01-18
- 0.0.5 — 2016-01-07
- 0.0.4 — 2016-01-07
- 0.0.3 — 2016-01-07
- 0.0.2 — 2016-01-07
- 0.0.1 — 2016-01-07

## README

easylog
=======

A wrapper around winston to simplify configuration and log beautifully.

## Table of Contents
<!-- :GenTocGFM -->
* [Motivation](#motivation)
* [Installation](#installation)
* [Usage](#usage)
* [Configuration](#configuration)
	* [Log the Logging](#log-the-logging)
* [API](#api)
	* [node_env](#node_env)
	* [easylog_level](#easylog_level)
	* [root_dir_files](#root_dir_files)
	* [cwd](#cwd)
	* [logdir](#logdir)
	* [root_label](#root_label)
	* [override_winston](#override_winston)
	* [injected_deps](#injected_deps)
	* [injected_deps.winston](#injected_depswinston)
	* [package_json](#package_json)
	* [config_file_candidates](#config_file_candidates)

## Motivation

[Winston](https://github.com/winstonjs/winston) is an excellent logging library
that consists of easy to understand and easy to hack components. Getting
started is relatively painless and there's a plethora of transports for various
endpoints like files, console, databases, cloud services...

What winston lacks is the possiblity to configure the components without a lot
of code. I found myself copy and pasting a wrapper class that sets up nice
console formatting, sane log file locations, timer/profiling etc. I wanted a
library that would make these customizations easy and whose behavior could be
driven by one or more configuration files rather than code. `easylog` is that
library.

## Installation

```
npm install --save easylog
```

## Usage

The module generates a default logging container and exports a constructor for child loggers.

The best way to use it is to pass it the current module. This way the logger
will know for which file it logs events:

```js
/* myFile.js */
var log = require('easylog')(module)

log.info("Life, Universe &c?", {'answer', 42});
```

![](./doc/screenshots/log-42.png)

## Configuration

`easylog` can be configured by a JSON object that conforms to a JSON schema file.
By default, the configuration will be searched, in order of preference:

* A file `easylog-development.json` or `easylog-production.json`, depending on your `$NODE_ENV`
* A file `easylog.json`
* An `easylog` entry in the `package.json`

The [full schema](./doc/schema-full.json) is comprehensive but you can specify
only fragments of the configuraiton in the mentioned locations, the default
config will be computed on the fly, see
[./doc/default-config.json](./doc/default-config.json) for a static copy of the
default configuration file.

### Log Patterns

`easylog` expects the log messages described as
[log-pattern](https://github.com/kba/log-pattern) macros. Please refer to the
[documentation of pre-defined
macros](https://github.com/kba/log-pattern/blob/master/MACROS.md) there.


The default pattern for the log entry is:

```js 
'[%levelColor(%pad{-5}(%LEVEL))] ' +
'%levelColor(%date)' +
' |%label| ' +
'%message' +
'%meta'
```

The default pattern for the label is:

```js
%pkg{name}' +
'%@{sep}(:)' +
'%@{name}(%path{%name})' +
'%?(%config{child})(' +
  '%@{sep}(#)' +
  '%@{child}(%config{child})' +
')'
```

### Log the Logging

It can be tedious to debug why logging isn't working the way it's supposed to.
You'd find yourself falling back to `console.log` et al to log the problems
that prevent logging. To prevent you from this particular type of yak-shaving,
`easylog` by default logs its own startup and every reload of configuration
with level `DEBUG`.

## API

### node_env

The environemnt, i.e. `development` or `production`. This overrides the
`NODE_ENV` environment variable and defaults to `development`.

### easylog_level

The log level of easylog itself. For debugging purposes, this is set to `debug`
by defualt. See [Log the Logging](#log-the-logging).

### root_dir_files
### cwd
### logdir
### root_label

The label of the root logger, by default `ROOT`.

### override_winston

If set, `easylog` will override the logger singleton that is returned when you
`require('winston')`. This has the advantage that it will also enable your
logging configuration for other logger that use winston. If set to `true` (the
default) then `winston.log` will be overridden with easylog's root logger's
`log` method.

### injected_deps
### injected_deps.winston
### package_json
### config_file_candidates

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