# log-ninja

> Handles logging for different environments: development, staging & production.

Latest version **2.0.4** (published 2017-05-11) · 0 weekly downloads

## Install

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

## 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 | 2.0.4 |
| Published | 2017-05-11 |
| First published | 2015-02-16 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Josh Cole |
| Maintainers | saikojosh |
| Keywords | log, logger, logging, console, output, debugging, level, fatal, error, warn, warning, info, debug, verbose |

## Links

- npm: https://www.npmjs.com/package/log-ninja
- Repository: https://github.com/SaikoJosh/Log-Ninja
- Homepage: https://github.com/SaikoJosh/Log-Ninja#readme
- Issues: https://github.com/SaikoJosh/Log-Ninja/issues
- npm.io page: https://npm.io/package/log-ninja

## Dependencies (1)

- [cli-color](https://npm.io/package/cli-color.md) 0.3.x

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

- 2.0.4 (latest) — 2017-05-11
- 2.0.3 — 2017-05-11
- 2.0.2 — 2017-05-04
- 2.0.1 — 2017-05-03
- 2.0.0 — 2017-05-03
- 1.1.1 — 2015-02-16
- 1.1.0 — 2015-02-16

## README

Log Ninja
=========

Handles colourful logging to the console for different log levels without needing to put if statements and console logs throughout your code.

```javascript
// No more of this:
if (process.env.NODE_ENV === 'development') { console.log('My log message.'); }

// Now we have this:
log.debug('My log message.');
```

# Quick Start
At the top of your application entry point you need to initialise Log-Ninja with a log level, before you require any other files in your application:

```javascript
const log = require('log-ninja').init('debug');

log.info('Some information...');
```

Then in any other files in your application you just require Log-Ninja again to get the already initialised version:

```javascript
const log = require('log-ninja');

// Will be output because "warn" has a lower log level than "debug".
log.warn('A warning 😮');

// Will NOT be output because "verbose" has a higher log level than "debug".
log.verbose('Lots and lots of detail.');
```

# Log Levels
Log-Ninja supports the following log levels:

| ID      | Level  | Function                             |
|---------|--------|--------------------------------------|
| fatal   | 0      | `log.fatal(string1, string2, ...)`   |
| error   | 1      | `log.error(string1, string2, ...)`   |
| warn    | 2      | `log.warn(string1, string2, ...)`    |
| info    | 3      | `log.info(string1, string2, ...)`    |
| debug   | 4      | `log.debug(string1, string2, ...)`   |
| verbose | 5      | `log.verbose(string1, string2, ...)` |
| silly   | 6      | `log.silly(string1, string2, ...)`   |

Each of the functions support multiple strings which will be concatenated together with spaces (the same way console.log() works).

## Output All Logs
If you inintialise Log-Ninja like `.init('verbose')` or `.init(6)` then ALL logs will be output to the console.

## Output Only Errors
If you inintialise Log-Ninja like `.init('error')` or `.init(1)` then only error and fatal logs will be output to the console.

## Turn Off Colours
If you don't want colours to be output you can pass a second parameter to `.init()` like so:

```javascript
const log = require('log-ninja').init('debug', {
	colours: false,
});
```

# Other Handy Functions
Log-Ninja comes with a few other functions to make logging to the console a little bit easier:

| Function                                 | Description |
|------------------------------------------|-------------|
| `log.title(string1, string2, ...)`       | Outputs an important message in bold and underlined. |
| `log.important(string1, string2, ...)`   | Outputs an important information in bold.   |
| `log.success(string1, string2, ...)`     | Outputs a success message. |
| `log.final(string1, string2, ...)`       | Outputs the final success message of an execution. |
| `log.json(object1, object2, ...objectN)` | Outputs JSON pretty printed for every object provided. |
| `log.space()`                            | Outputs a blank line. |
| `log.raw(aSingleString)`                 | Outputs a single string to stdout without any colours and without a trailing line break. |
| `log.rawError(aSingleString)`            | Outputs a single string to stderr without any colours and without a trailing line break. |
| `log.box(status, message)`               | Outputs a status followed by a message. Valid statuses are "ok", "fail", "warn" and "info". |

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