# log-control

> Logging util focused on fine-grained control of log levels of different components.

Latest version **0.0.2** (published 2021-03-02) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2021-03-02 |
| First published | 2021-03-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Remi Alkemade |
| Maintainers | rremigius |
| Keywords | log, logging, levels, log levels |

## Links

- npm: https://www.npmjs.com/package/log-control
- Repository: https://github.com/rremigius/log-control
- Homepage: https://github.com/rremigius/log-control.git
- Issues: https://github.com/rremigius/log-control.git#issues
- npm.io page: https://npm.io/package/log-control

## Dependencies (5)

- [esm](https://npm.io/package/esm.md) ^3.2.25
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [@types/chai](https://npm.io/package/@types/chai.md) ^4.2.15
- [@types/mocha](https://npm.io/package/@types/mocha.md) ^8.2.1
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.168

## 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.0.2 (latest) — 2021-03-02
- 0.0.1 — 2021-03-02

## README

LogControl
===

LogControl is a logging utility focused at fine-grained control of logging levels of hierarchical components.

Typescript supported.

## Features

- Each module/component/file can have its own logger, messages prefixed with a specific name.
- Hierarchically organised, so log levels can be set for an entire tree of loggers.
- Configurable driver, for interoperability with other log utilities.

## Getting Started

### Getting a Log instance

```javascript
let log = Log.instance("mycomponent");
log.info("Logging works!");
```

### Log levels for different instances

```javascript
let log1 = Log.instance("component1");
let log2 = Log.instance("component2");

log1.setLevel(LogLevel.OFF);
log1.info("This will not be logged.");

log2.info("This will be logged.");
```

### Hierarchical loggers

```javascript
let carLog = Log.instance("car");
let interiorLog = Log.instance("car/interior");
let seatingLog = Log.instance("car/interior/seating");
let engineLog = Log.instance("car/engine");

interiorLog.setLevel(LogLevel.OFF);

carLog.info("This will be logged.");
interiorLog.info("This will *not* be logged.");
seatingLog.info("This will *not* be logged.");
engineLog.info("This will be logged.");
```

A hierarchy can also be created from instances themselves:

```javascript
let carLog = Log.instance("car");
let engineLog = carLog.instance("engine");
console.log(engineLog === Log.instance("car/engine")); // true
```

### Setting a driver

If an existing logging util is already being used, the Log Control utility can be applied on top of it, by setting
the Log driver:

```javascript
let myDriver = {
    trace:(...args) => { /*...*/ },
    debug:(...args) => { /*...*/ },
    log:(...args) => { /*...*/ },
    info:(...args) => { /*...*/ },
    warn:(...args) => { /*...*/ },
    error:(...args) => { /*...*/ }
}
Log.instance().setDriver(myDriver);
Log.instance().info("This will be logged by myDriver");
```

Similar to the log level, the driver is applied hierarchically:

```javascript
let carLog = Log.instance("car");
let engineLog = Log.instance("car/engine");
let exhaustLog = Log.instance("car/engine/exhaust");
let dashLog = Log.instance("car/dashboard");

engineLog.setDriver(myDriver);

engineLog.info("Logged by myDriver");
exhaustLog.info("Logged by myDriver");
carLog.info("Still logged by console");
dashLog.info("Still logged by console");

```

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