# yocto-logger

> Ready to use logger utility based on winston.

Latest version **3.0.0** (published 2018-02-14) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install yocto-logger
pnpm add yocto-logger
yarn add yocto-logger
bun add yocto-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 | 3.0.0 |
| Published | 2018-02-14 |
| First published | 2015-09-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.9.4 |
| Dependencies | 9 |
| Unpacked size | 28.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yocto SAS |
| Maintainers | yocto |
| Keywords | logging, winston, sysadmin, tool, transport, log |

## Links

- npm: https://www.npmjs.com/package/yocto-logger
- Repository: https://github.com/yoctore/yocto-logger
- Homepage: https://github.com/yoctore/yocto-logger#readme
- Issues: https://github.com/yoctore/yocto-logger/issues
- npm.io page: https://npm.io/package/yocto-logger

## Dependencies (9)

- [uuid](https://npm.io/package/uuid.md) ^3.0.1
- [chalk](https://npm.io/package/chalk.md) ^2.3.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.2
- [moment](https://npm.io/package/moment.md) ^2.17.1
- [promise](https://npm.io/package/promise.md) ^8.0.1
- [winston](https://npm.io/package/winston.md) ^2.3.0
- [yocto-utils](https://npm.io/package/yocto-utils.md) ^1.3.0
- [string-format](https://npm.io/package/string-format.md) ^0.5.0
- [winston-daily-rotate-file](https://npm.io/package/winston-daily-rotate-file.md) ^1.4.0

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

- 3.0.0 (latest) — 2018-02-14
- 2.0.0 — 2016-12-08
- 1.1.6 — 2016-04-25
- 1.1.5 — 2016-03-31
- 1.1.4 — 2016-03-31
- 1.1.3 — 2016-03-25
- 1.1.2 — 2016-02-09
- 1.1.1 — 2015-11-03
- 1.1.0 — 2015-10-27
- 1.0.4 — 2015-09-30
- 1.0.3 — 2015-09-30
- 1.0.2 — 2015-09-25
- 1.0.1 — 2015-09-24
- 1.0.0 — 2015-09-18

## README

[![NPM](https://nodei.co/npm/yocto-logger.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/yocto-logger/)

![alt text](https://david-dm.org/yoctore/yocto-logger.svg "Dependencies Status")
[![Code Climate](https://codeclimate.com/github/yoctore/yocto-logger/badges/gpa.svg)](https://codeclimate.com/github/yoctore/yocto-logger)
[![Test Coverage](https://codeclimate.com/github/yoctore/yocto-logger/badges/coverage.svg)](https://codeclimate.com/github/yoctore/yocto-logger/coverage)
[![Issue Count](https://codeclimate.com/github/yoctore/yocto-logger/badges/issue_count.svg)](https://codeclimate.com/github/yoctore/yocto-logger)
[![Build Status](https://travis-ci.org/yoctore/yocto-logger.svg?branch=master)](https://travis-ci.org/yoctore/yocto-logger)



## Overview

This module is a part of yocto node modules for NodeJS. 

Please see [https://www.npmjs.com/~yocto](https://www.npmjs.com/~yocto) for complete list of available module (completed day after day).

This module manage your own logger request on your node app.

This module his based on [winston](https://www.npmjs.com/package/winston) package.

**IMPORTANT : This module is not a complete reimplantation of winston** we only use winston for the core process.

**IMPORTANT : This module shared logger by default in next major release group logger will be add**

## Motivation

In all of our project we use a logger library like winston. But all the time we need to
configure again and again the same library. 

That why we decided to create yocto-Logger.

This tool is designed to be a very very simple and pre-configured and ready to use tool
based on the universal logging library winston.

## Configuration : console transport

By default a console is configured with these options : 
(Cf. winston & momentjs documentation for more details)

```javascript
{
  level             : 'debug',
  handleExceptions  : false,
  json              : false,
  showLevel         : true,
  silent            : false,
  timestamp         : function () {
    // return special timestamp format
    return moment().format('YYYY/MM/DD HH:mm:ss');
  }
};
```
## Configuration : daily rotate transport

By default a daily rotate transport is configured with these options : 
(Cf. winston & momentjs documentation for more details)

```javascript
{
  name              : 'default-daily-rotate-transport',
  level             : 'verbose',
  dirname           : './',
  filename          : uuid.v4(), // default name if name is not given
  handleExceptions  : true,
  json              : false,
  maxsize           : 5242880,
  maxFiles          : 5,
  colorize          : true,
  datePattern       : '-yyyy-MM-dd.log',
  timestamp         : function () {
    // return special timestamp format
    return moment().format('YYYY/MM/DD HH:mm:ss');
  }
};
```

## Logging Method

 Avaiblable methods are : 
 
- error (for error message)
- warning (for warning message)
- info (for information message)
- debug (for debug message)
- verbose (for normal message)

```javascript
var logger = require('yocto-logger');
// error message
logger.error('Hello world');
// warning message
logger.warning('Hello world');
// info message
logger.info('Hello world');
// debug message
logger.debug('Hello world');
// verbose message
logger.verbose('Hello world');
// banner message
logger.banner('Hello world');
```

## Banner Method 

To display on console.log a more significant message we implemened a banner method.
You can customize style (color and background color) of message but is not save on available transports.

```javascript
var logger = require('yocto-logger');
// banner usage
logger.banner("Banner customized",{ color: "red" , bgColor: "white" });
```

## Transport : Adding a new daily rotate transport

```javascript
var logger = require('yocto-logger');

// add new daily rotate transport with default config
logger.addDailyRotateTransport();

// add new daily rotate transport and process new action when async is finish
logger.addDailyRotateTransport().then(function(success) {
    // your process here
}, function(error) {
    // error process here
});

// add new daily transport on specific path + changing filename and more options
logger.addDailyRotateTransport('/your-new-path-here', 'your-file-name-here', {});
```

## Change level manually

You can change current logger level manually by method `setLogLevel(name)`.

Property `name` of this function must be one of these values :

 
- error (for error message)
- warning (for warning message)
- info (for information message)
- debug (for debug message)
- verbose (for normal message)

For example if we need to set current logger instance to `error` level : 

```javascript
var logger = require('yocto-logger');

logger.setLogLevel('error');
// YOUR Extra code here
```

## Utility Methods

For a better usage we can interact with all transport by utility methods.
Methods available are : 

- more  :to change the log level to a higher level
- less  : to change the log level to a less level
- enableConsole : to enable console transport if is disable
- disableConsole : to disable console transport if is enable
- enableExceptions : to enable catch exception on logger if is disable
- disableExceptions : to disable catch exception on logger if is enable

```javascript
var logger = require('yocto-logger');

// Less & more - initial level is debug
logger.more(); // level change to verbose
logger.less(); // level change to debug

// Others method
logger.enableConsole();
logger.disableConsole();
logger.enableExceptions();
logger.disableExceptions();
```

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