# silence-log

> Agnostic logger factory to unify them all, without any Sauron

Latest version **0.2.0** (published 2020-06-04) · All Right Reserved license · 0 weekly downloads

## Install

```sh
npm install silence-log
pnpm add silence-log
yarn add silence-log
bun add silence-log
```

## 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.2.0 |
| Published | 2020-06-04 |
| First published | 2016-04-30 |
| Weekly downloads | 0 |
| License | All Right Reserved |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Francois A.R. Vilain |
| Maintainers | farvilain |

## Links

- npm: https://www.npmjs.com/package/silence-log
- Repository: https://github.com/farvilain/silence-log
- Homepage: https://github.com/farvilain/silence-log#readme
- Issues: https://github.com/farvilain/silence-log/issues
- npm.io page: https://npm.io/package/silence-log

## Recent versions

- 0.2.0 (latest) — 2020-06-04
- 0.0.4 — 2016-08-19
- 0.0.3 — 2016-05-09
- 0.0.2 — 2016-05-09
- 0.0.1 — 2016-04-30

## README

# silence-log

A tiny framework that provide a log facade, inspired by the Java [SLF4J](http://www.slf4j.org/).


## Motivation

Which log framework would you use when creating your own Node library?
[Bunyan](https://github.com/trentm/node-bunyan) ?
[Winston](https://github.com/winstonjs/winston) ?
[Log](https://www.npmjs.com/package/log) ?
...?

There is no right answer because you try to take a decision not in your scope.

Imagine that John build an application that uses:
* Your framework, using Bunyan
* Another one, using Winston.

John now have to handle differents logging framework.


This framework follow the idea of SLF4J: framework should use an interface and applications decides which implementation they want.


## How does it work?

### Making some logs

After installing `npm install --save silence-log`, you can just do this kind of code.

```javascript

var engineLogger = require('silence-log').get("pegasus.engine");
engineLogger.app({
	name: 'MyApp'
});
engineLogger.warn("engine overheating");

```

The `get` method gives youe the specific logger, creating it if needed. The name provided is hierarchically constructed, with 'dot' separator.
Try to always start your loggers names with your npm project name.

Methods available to log are:
* trace
* debug
* info
* warn
* error

That's it.


### Configurating

In your final application or in your library testing code, you have to provide a configuration to really see your logs.

First of all, require silence-log as soon as possible, to ensure that your installed version will be used event if other dependencies used another one.
Then, require a configuration file.

The easy way is to create a `log.js` file and require it in the first line of your application entry point.


```javascript

var factory = require('silence-log');

function consoleAppender(app, loggerName, level, msg){
	console.log(`${level.toUpperCase().padStart(6, ' ')} [${app.name}] ${loggerName} :: ${msg}`);
}

//Define the root logger appender (and any child) on debug, so for [error, warrn, info, debug] but not trace
factory.get('').addAppender("debug", consoleAppender);

//Remove this appender from anotherFramework (and any child) from info, so [info, debug, trace] but allow it for [error, warn]
factory.get('anotherFramework').removeAppender('info', consoleAppender);

```

### Binding with other framework

It's not yet done but you can provide me help

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