# @rabbitcc/log

> A log tool

Latest version **0.4.6** (published 2018-10-19) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @rabbitcc/log
pnpm add @rabbitcc/log
yarn add @rabbitcc/log
bun add @rabbitcc/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.4.6 |
| Published | 2018-10-19 |
| First published | 2018-08-07 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 95.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Rabbit |
| Maintainers | rabbitcc |

## Links

- npm: https://www.npmjs.com/package/@rabbitcc/log
- npm.io page: https://npm.io/package/@rabbitcc/log

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^6.0.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [isomorphic-ws](https://npm.io/package/isomorphic-ws.md) ^4.0.1

## Recent versions

- 0.4.6 (latest) — 2018-10-19
- 0.4.5 — 2018-10-19
- 0.4.4 — 2018-10-19
- 0.4.3 — 2018-10-19
- 0.4.2 — 2018-10-19
- 0.4.1 — 2018-08-13
- 0.4.0 — 2018-08-13
- 0.3.4 — 2018-08-08
- 0.3.3 — 2018-08-08
- 0.3.2 — 2018-08-08
- 0.3.1 — 2018-08-08
- 0.3.0 — 2018-08-08
- 0.2.6 — 2018-08-07
- 0.2.5 — 2018-08-07
- 0.2.4 — 2018-08-07
- … 1 more at https://npm.io/package/@rabbitcc/log/versions

## README

Yet anthor logger tool
----

Works on Nodejs and Browsers

Terminal:

![Terminal](https://user-images.githubusercontent.com/5752902/43772728-a6ec9fbe-9a75-11e8-95bc-7d6fe7a9aa72.png)

Browser:

![browser](https://user-images.githubusercontent.com/5752902/43772620-47e41182-9a75-11e8-9632-68d5944db477.png)


## Install

```sh
npm i -D @rabbitcc/log
```

## Usage

```js
import log from '@rabbitcc/log'

log.info('name', 'action', 'contents')
```


### Setup logger level

```js
// via cross-env scripts

cross-env LOGGER_LEVEL=DEBUG
```

Or if you want works on browser, can pass the evn via `webpack.EnvironmentPlugin`

```js
plugins: [
  //...other plugins

  new EnvironmentPlugin([ 'LOGGER_LEVEL' ]),

  // or pass default level if not set

  new EnvironmentPlugin({ LOGGER_LEVEL: process.env.LOGGER_LEVEL }),
]
```

You can pass log level by number and string type, below syntax are vaild.

```js
cross-env LOGGER_LEVEL=warn
cross-env LOGGER_LEVEL=WARN
cross-env LOGGER_LEVEL=40
```

If `process.env.DEBUG` flag was found, the logger level is set to `DEBUG`.

There is some build-in logger levels:

| NAME  | WEIGHT | DEFAULT? |
|-------|--------|----------|
| trace | 100    |   no     |
| debug | 80     |   no     |
| info  | 60     |   yes    |
| warn  | 40     |   no     |
| error | 20     |   no     |
| fatal |  0     |   no     |

By the way, the `FATAL` level will highlight by background color.





### Feature, log with origin file position


![show origin file position](https://user-images.githubusercontent.com/5752902/44018351-0b1d63dc-9f0e-11e8-9b02-7625db60f730.png)

Enable this feature need setup as babel plugins:

```js
{
  "plugins": ["@rabbitcc/log/inject-position"]
}

// setup with options

{
  "plugins": [["@rabbitcc/log/inject-position", {
    // ...options see below
  }]]
}
```

The inject position plugin options:

```js
type InjectPositionPluginOptions = {
  test?: RegExp = /^@rabbitcc\/log/
}
```

In browser, you need to add folder to **chrome devtools workspace**.

![browser workspace](https://user-images.githubusercontent.com/5752902/44018496-925f25c4-9f0e-11e8-8eac-01db00148c0d.gif)

This feature also works on terminal. Your terminal should support hyperlinks.

![cmder hyperlinks](https://user-images.githubusercontent.com/5752902/44021314-10aac3d6-9f17-11e8-9c9b-dd264dc058a5.gif)



### Feature, log sync on terminal and browser via `webpack-hot-client` socket server

If you want log both on terminal and browser, like this:

![sync with terminal and browser](https://user-images.githubusercontent.com/5752902/44030168-88fd55a4-9f32-11e8-9255-bf01f5cd5840.gif)

You can use `createSocket` with `webpack-serve` via WebSocket.

Setup browsers:

```js
import log, { createSocket } from '@rabbitcc/log/socket'

if('production' !== process.env.NODE_ENV) {
  createSocket({ /* ...options see below */ })
}

log.info('name', 'action', 'contents')
```

And apply logger to `webpack.config.js`:

```js
import { createSocket } from '@rabbitcc/log/socket'

serve: {
  on: {
    listening() {
      createSocket({ /* ...options see below */ })
    }
  }
}
```

The `createSocket` options:

```js
type CreateSocketOptions = {
  /**
   * socket url, default to webpack-hot-client ws socket string
   */
  socket?: string = 'ws://localhost:8081'
}
```

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