Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myronliu347/log.js
前端日志工具,提供简易的API,可以通过配置 level 和 appender 来输出日志
https://github.com/myronliu347/log.js
Last synced: 3 months ago
JSON representation
前端日志工具,提供简易的API,可以通过配置 level 和 appender 来输出日志
- Host: GitHub
- URL: https://github.com/myronliu347/log.js
- Owner: myronliu347
- License: mit
- Created: 2016-08-03T04:21:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-18T00:20:26.000Z (over 8 years ago)
- Last Synced: 2024-10-02T02:59:56.435Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 43.9 KB
- Stars: 17
- Watchers: 8
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# log.js
前端日志工具库,简单的api,可以通过配置不同的 *level* 和 *appender* 来输出日志## 开始使用
### 安装
```html
```
或者
```shell
npm install si-log --save
```### 使用
```javascript
siLog.debug('test debug level');
siLog.info('test info level');
siLog.warn('test warn level');
siLog.error('test error level');
```![](run-img.png)
CommonJs
```javascript
var siLog = require('si-log')
siLog.debug('test debug level');
siLog.info('test info level');
siLog.warn('test warn level');
siLog.error('test error level');
```ES6
```javascript
import siLog from 'si-log'siLog.debug('test debug level');
siLog.info('test info level');
siLog.warn('test warn level');
siLog.error('test error level');
```### 配置输出方式
```javascript
siLog.config({
level: true
}); // output all level
siLog.config({
level: false
}); // No output
siLog.config({
level: ['error']
}); // only output error level
siLog.config({
level: ['error', 'warn']
}); // only output error or warn
```### 创建多个log对象
```javascript
// render.js
var log = siLog.create('render.js')
log.debug('test in render.js output')// [render.js]: test in render.js output
```### 配置输出方式
```javascript
siLog.config({
appenders: {
// console
console: {
printTime: true
}
// ...more
}
})
```### 自定义输出方式
```javascript
siLog.appender('test', fucntion (op) {
return function (logInfo) {
document.write('name:' + loginfo.name);
if (op.printTime) document.write('time:' + loginfo.timeStr);
document.write('args:' + JSON.stringify(logInfo.args));
}
});siLog.config({
appenders: {
test: { // use test output log
printTime: true
}
}
})
```## API
### debug([args])
相当于 `console.log`
### info([args])
相当于 `console.info`
### warn([args])
相当于 `console.warn`
### error([args])
相当于 `console.error`
### create([name])
创建新的 Log 实例
### appender([name, appender])
注册一个 appender
### config(options)
修改配置
## License
[MIT](http://opensource.org/licenses/MIT)
Copyright (c) 2016 myron