# logger3

> A simple but in-depth logger. Customize by composition.

Latest version **1.0.0** (published 2019-05-17) · MIT license · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2019-05-17 |
| First published | 2019-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dave Caruso |
| Maintainers | imdaveead |

## Links

- npm: https://www.npmjs.com/package/logger3
- npm.io page: https://npm.io/package/logger3

## Dependencies (1)

- [chalk](https://npm.io/package/chalk.md) ^2.4.2

## Recent versions

- 1.0.0 (latest) — 2019-05-17

## README

# logger3
> a simple but in depth logger for node.js, Customize by Composition.

The idea for this tool is composing logging functions, so you can make the logs look exactly
how you want or need them to.

## Usage
You just import the module, and call log.
```javascript
const log = require('logger3');

log('Hello World');
```

That's not interesting, lets compose a simple prefix in front of the message.
```javascript
const log = require('logger3');

const prefixed = log.prefix('[DEBUG]');

prefixed('Hello World, Debug Edition');
// -> [DEBUG] Hello World, Debug Edition
```

Prefixes can also be functions that get executed every time a log happens, this
can be used for timestamps.
```javascript
const log = require('logger3');

const timestamped = log.prefix(() => `[${Date.now()}]`);

timestamped('Hello World, Timestamped');
// -> [1558056117302] Hello World, Debug Edition
//
// Will vary depending when you run it.
```

You can also chain the logging modifiers
```javascript
const log = require('logger3');

const chained = log.prefix(() => `[${Date.now()}]`).suffix('[SUFFIX]');

chained('Hello World');
// -> [1558056117302] Hello World, Debug Edition [SUFFIX]
//
// Will vary depending when you run it.
```

There are also a bunch of built in formatters, and colors. Colors are based on the `chalk` module,
so you can use their api of chaining properties.
```javascript
const log = require('logger3');
const { format, color } = log;

const red = log.make(color.red);
const brackets = log.make(format.paren);
const time = log.prefix(format.bracket(format.time));

red('Hello World');
brackets('Hello World');
time('Hello World');

// Hello World        (in red)
// (Hello World)
// [21:26:35] Hello World
```

When using in a project, you should create a file where you compose all your log functions, which
are used by the rest of the program.
```js
const log = require('logger3');
const { format, color } = log;

const bracketTime = format.bracket(format.time);

module.exports.info = log.make(color.blue).prefix('[INFO] ').prefix(bracketTime);
module.exports.warn = log.make(color.yellow).prefix('[WARN] ').prefix(bracketTime);
module.exports.error = log.make(color.red).prefix('[ERROR]').prefix(bracketTime);
module.exports.debug = log.make(color.magenta).prefix('[DEBUG]').prefix(bracketTime);
```

## API
### Logger
Get a blank logger with `const log = require('logger3')`;
- `log()` Logs to the console
- `log.prefix(prefix)` Applies a prefix, returns a logger
- `log.suffix(suffix)` Applies a suffix, returns a logger
- `log.make(maker)` Applies a transformer function, returns a logger

### Formatters (log.format)
Get the formatters object with `const format = require('logger3').format;`;
- `format.bracket(item)` Formats text with \[brackets\]
- `format.paren(item)` Formats text with (parenthesis)
- `format.brace(item)` Formats text with {braces}
- `format.createFormatter((item) => `${item}`)` Creates a formatter, used by the other formatters to ensure a string is passed
- `format.timestamp()` returns the timestamp (see `Date.now`);
- `format.time()` returns the time formatted to `HH:MM:SS`;

### Colors
Get the colors object with `const color = require('logger3').color;`. You can chain the properties to
apply a color, background, and other text decoration, provided your terminal supports it.

Available Properties
- `reset`
- `bold`
- `dim`
- `italic`
- `underline`
- `inverse`
- `hidden`
- `strikethrough`
- `visible`
- `black`
- `red`
- `green`
- `yellow`
- `blue`
- `magenta`
- `cyan`
- `white`
- `gray`
- `redBright`
- `greenBright`
- `yellowBright`
- `blueBright`
- `magentaBright`
- `cyanBright`
- `whiteBright`
- `bgBlack`
- `bgRed`
- `bgGreen`
- `bgYellow`
- `bgBlue`
- `bgMagenta`
- `bgCyan`
- `bgWhite`
- `bgBlackBright`
- `bgRedBright`
- `bgGreenBright`
- `bgYellowBright`
- `bgBlueBright`
- `bgMagentaBright`
- `bgCyanBright`
- `bgWhiteBright`

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