# node-bugjs

> debug for node.js .

Latest version **2.0.1** (published 2018-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-bugjs
pnpm add node-bugjs
yarn add node-bugjs
bun add node-bugjs
```

## 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.1 |
| Published | 2018-04-21 |
| First published | 2018-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 35.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | lanyue |
| Maintainers | lanyue |
| Keywords | log, node-bugjs, debug |

## Links

- npm: https://www.npmjs.com/package/node-bugjs
- Repository: https://github.com/mengdu/node-bugjs
- Homepage: https://github.com/mengdu/node-bugjs#readme
- Issues: https://github.com/mengdu/node-bugjs/issues
- npm.io page: https://npm.io/package/node-bugjs

## 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.1 (latest) — 2018-04-21
- 2.0.0 — 2018-01-14

## README

# node-bugjs

node-bugjs 是 node.js 的一个调试工具。

+ 支持5中主题样式（白，红，绿，黄，蓝）
+ 显示当前输出日志代码行号，方便开发调试
+ 支持定义log回调处理，实现log记录功能


> 注：已经不支持 [log-mini@1.0.0](https://www.npmjs.com/package/log-mini) 的用法。


**install**

```bat
npm install -S node-bugjs
```

```js
const bugjs = require('node-bugjs')('http')

bugjs.log('wellcome')
```



## api

```js
const Bugjs = require('node-bugjs')

const bugjs = new Bugjs(options || 'categorie')
// or
const bugjs = Bugjs(options)
```


+ **Bugjs.prototype.config(options)** 配置
+ **Bugjs.prototype.log(any, any, ...)**
+ **Bugjs.prototype.info(any, any, ...)**
+ **Bugjs.prototype.success(any, any, ...)**
+ **Bugjs.prototype.error(any, any, ...)**
+ **Bugjs.prototype.warn(any, any, ...)**
+ **Bugjs.prototype.storeHandler = (logs) => {}** 定义log回调，可以用来实现记录日志
+ **Bugjs.Callsites** 获取调用栈对象，可以new CallSite()创建


**options：**

+ **options.console** 打印到控制台，默认true
+ **options.store** 是否开启写store回调，默认false
+ **options.categorie** 标签，默认''
+ **options.categorieColor** 标签样式，请看支持的 styles
+ **options.debug** 是否开启debug模式，默认 true (`process.env.NODE_ENV !== 'production'`)，开启后会显示当前调用文件行号
+ **options.absolute** 显示文件路径是否是绝对路径，默认 false
+ **options.bright** 是否亮色，默认 false
+ **options.date** 是否显示时间，默认 false
+ **options.dateColor** 显示时间样式，默认 'blue'，请看支持的 styles
+ **options.filenameColor** 文件名样式，默认 'gray'，请看支持的 styles
+ **options.callIndex** 指定调用栈序号，共10，默认2


可以运行 `demo.js` 查看效果


> 注：显示文件名和行号会影响js性能，上线项目请自行删掉log，或者配置debug为false


## 记录日志

```js
// 记录到日志
bugjs.storeHandler = function (log) {
  var logs = []
  for (var key in log) {
    if (key !== 'logs') {
      logs.push(log[key])
    }
  }
  logs.push(' ')
  fs.appendFileSync(this.categorie + '.log', logs.concat(log.logs).join('') + '\n')
}

```

## 支持样式

```text
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

```

## 效果图


![截图1][1]

[1]: imgs/20180114161250.png


## other

[colors](https://github.com/Marak/colors.js)
[V8 stack trace API](#)

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