# two-log

> ora and winston , just two logger, if debug

Latest version **0.2.1** (published 2018-08-24) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2018-08-24 |
| First published | 2018-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=4 |
| Dependencies | 3 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | chinanf-boy |
| Maintainers | yobrave1995 |
| Keywords | log, ora, winston |

## Links

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

## Dependencies (3)

- [ora-min](https://npm.io/package/ora-min.md) ^1.0.0
- [winston](https://npm.io/package/winston.md) ^2.4.2
- [get-module-name](https://npm.io/package/get-module-name.md) 0.0.1

## 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.2.1 (latest) — 2018-08-24
- 0.2.0 — 2018-08-21
- 0.1.2 — 2018-08-20
- 0.1.1 — 2018-08-19
- 0.1.0 — 2018-08-19
- 0.0.11 — 2018-08-15
- 0.0.10 — 2018-06-11
- 0.0.9 — 2018-05-30
- 0.0.8 — 2018-05-30
- 0.0.7 — 2018-05-30
- 0.0.6 — 2018-05-30
- 0.0.5 — 2018-05-30
- 0.0.4 — 2018-05-28
- 0.0.3 — 2018-05-28
- 0.0.2 — 2018-05-27
- … 1 more at https://npm.io/package/two-log/versions

## README

# two-log [![Build Status](https://travis-ci.org/chinanf-boy/two-log.svg?branch=master)](https://travis-ci.org/chinanf-boy/two-log) [![codecov](https://codecov.io/gh/chinanf-boy/two-log/badge.svg?branch=master)](https://codecov.io/gh/chinanf-boy/two-log?branch=master) [![explain](http://llever.com/explain.svg)](https://github.com/chinanf-boy/two-log-explain)

> switch `ora` and `winston` , if `debug == true` log => `winston`, else log => `ora`

## install

```
npm i two-log
```

## cli demo

```
npm i -g two-log-cli
```

<p>
<img src="./imgs/demo1.gif" width="40%">
<img src="./imgs/demo2.gif" width="40%">
</p>

- [two-log-cli](https://github.com/chinanf-boy/two-log-cli)

## Usage

```js
// cli.js
const twoLog = require('two-log');
let D = cli.flags['D'] ? true : false;

let l = twoLog(D);

let useWhat = !D ? 'ora' : 'winston';

l.start(`hello there debug:${D} , then use ${useWhat}`, {
	ora: 'red',
	log: 'error',
});

let t = 5000;

setTimeout(() => {
	l.text(`ora:green, log:debug and ${t} i will stop `, {
		ora: 'green',
	});

	l.one('just show one time ora');
}, t - 3000);

setTimeout(() => {
	l.text(`ora:green, log:debug and ${t} only show log style `, {
		ora: 'green',
		only: 'log',
	});
}, t - 2000);

setTimeout(() => {
	l.stop(`${t}ms , ok i fail if ora `, { ora: 'fail', log: 'debug' });
}, t);
```

### l.start === loggerStart

### l.text === loggerText

### l.stop === loggerStop

### l.one === oneOra

> logger`***` use for other module without `l = twoLog(D)` init

---

## API

### twoLog(debug, userUser):log

#### debug

| name: | debug             |
| ----- | ----------------- |
| Type: | `boolean`         |
| Desc: | debug for two log |

#### userUse(api)

| name:    | userUse                        |
| -------- | ------------------------------ |
| Type:    | `function(api)`                |
| Default: | `undefined`                    |
| Desc:    | reset winston options for user |

##### api

| name:       | api             |
| ----------- | --------------- |
| Type:       | `object`        |
| Desc:       | api for user    |
| api.log:    | log === winston |
| api.setLog: | winston options |

<details>

<summary>
api examples
</summary>

```js
let userUse = api => {
	let winston = api.log;
	let wopts = {
		level: 'info',
	};
	api.setLog(wopts);
};

let l = log(true, userUse);
// winston level change
```

two-log default winston options

```js
let defaultWinston = {
	level: 'debug',
	transports: [
		new winston.transports.Console({
			datePattern: '.yyyy-MM-ddTHH-mm',
			colorize: true,
		}),
		new winston.transports.File({
			filename: `${pkg.name}.log`,
			handleExceptions: true,
			maxsize: 52000,
			maxFiles: 1,
			level: 'info',
			colorize: true,
		}),
	],
};
```

</details>

---

### log

| name:    | log                     |
| -------- | ----------------------- |
| Type:    | `any`                   |
| Desc:    | log api                 |
| Default: | `{ start, text, stop }` |
| Details: | `start === loggerStart` |
| Details: | `text === loggerText`   |
| Details: | `stop === loggerStop`   |
| Details: | `one === oneOra`        |

---

### loggerStart(str, options)

#### str

| name: | str      |
| ----- | -------- |
| Type: | `string` |
| Desc: | log text |

#### options

| name:         | options                                    |
| ------------- | ------------------------------------------ |
| Type:         | `any`                                      |
| Default:      | `{ ora: 'yellow', log: 'debug', only:"" }` |
| Desc:         | log text                                   |
| options.ora:  | ora color                                  |
| options.log:  | winston show log level                     |
| options.only: | only one {'ora' \| 'log'} can use          |

### loggerText(str, options)

#### str

| name: | str      |
| ----- | -------- |
| Type: | `string` |
| Desc: | log text |

#### options

| name:         | options                                    |
| ------------- | ------------------------------------------ |
| Type:         | `any`                                      |
| Default:      | `{ ora: 'yellow', log: 'debug', only:"" }` |
| Desc:         | log text                                   |
| options.ora:  | ora color                                  |
| options.log:  | winston show log level                     |
| options.only: | only one {'ora' \| 'log'} can use          |

### loggerStop(str, options)

#### str

| name: | str      |
| ----- | -------- |
| Type: | `string` |
| Desc: | log text |

#### options

| name:         | options                                                                  |
| ------------- | ------------------------------------------------------------------------ |
| Type:         | `any`                                                                    |
| Default:      | `{ ora: '', log: 'debug', only:"" }`                                     |
| Desc:         | log text                                                                 |
| options.ora:  | ora {`fail\|succeed\|warn`} https://github.com/sindresorhus/ora#instance |
| options.log:  | winston show log level                                                   |
| options.only: | only one {'ora' \| 'log'} can use                                        |

### oneOra(str, options)

#### str

| name: | str      |
| ----- | -------- |
| Type: | `string` |
| Desc: | ora text |

#### options

| name:          | options                                                                  |
| -------------- | ------------------------------------------------------------------------ |
| Type:          | `any`                                                                    |
| Default:       | `{ color: 'yellow', end: 'succeed' }`                                    |
| Desc:          | log text                                                                 |
| options.end:   | end {`fail\|succeed\|warn`} https://github.com/sindresorhus/ora#instance |
| options.color: | color                                                                    |

---

## use by

- [node-modules-size](https://github.com/chinanf-boy/node-modules-size) show node_modules hole size
- [doc-templite](https://github.com/chinanf-boy/doc-templite) multi-md-file with templite tool

## License

MIT © [chinanf-boy](http://llever.com)

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