Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ccjoe/xlog

js log info collection and trace, show it by call show()
https://github.com/ccjoe/xlog

Last synced: 18 days ago
JSON representation

js log info collection and trace, show it by call show()

Awesome Lists containing this project

README

        

## XLog
_XLog_ is a log management by PROD or DEV,
- IN PROD Mode, just collect the log info, donot print in console
- IN DEV Mode, console info will be show real time
- IN CLOSE Mode, console will be not effected

## Feature
- log ui
- log level
- log group and sort by time
- log find and filter
- log show by real-time(DEV) or manual call at console(PROD)
- error catch auto

## Example
xlog example

## Classes


XLog


## Members


LOG


XLog - https://github.com/ccjoe/XLog



## XLog
**Kind**: global class

* [XLog](#XLog)
* [new XLog(opt)](#new_XLog_new)
* _instance_
* [.init()](#XLog+init)
* [.size()](#XLog+size) ⇒ obejct
* [.get(level)](#XLog+get) ⇒ object
* [.set(level)](#XLog+set)
* [.show(level, [sort])](#XLog+show)
* [.find(str, level)](#XLog+find)
* [.reset(level)](#XLog+reset)
* [.catch(f)](#XLog+catch) ⇒ function
* [.catchModule(m)](#XLog+catchModule)
* _static_
* [.LOG](#XLog.LOG) : enum

### new XLog(opt)

```js
eg: var xLog = new XLog(opt)
```

create a XLog instance

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| opt | object | | arguments object |
| [opt.level] | number | 3 | log level [LOG.LEVEL](LOG.LEVEL) below level not show auto or manual, but set() to change LEVEL |
| [opt.mode] | string | "DEV" | 'CLOSE' OR 'DEV' OR 'PROD' [LOG.MODE](LOG.MODE) DEV mode show log realtime, PROD mode show log manual by sh
ow() method CLOSE will be all Xlog.js and error monitor |
| [opt.send] | function | function(){} | if u need to send log to remote, u need to define send function |

### Collection Log Data(pls see: run index.html or visit test.js)

```js

log.emergency('this is show by log.emergency')
log.alert('this is show by log.alert')
log.critical('this is show by log.critical')
log.error('this is show by log.error')
log.warn('this is show by log.warn')
log.notice('this is show by log.notice')
log.info('this is show by log.info')
log.log('this is show by log.log')

log.add(0, 'this is a 0 by log.add')
log.add(1, 'this is a 1 by log.add')
log.add(2, 'this is a 2 by log.add')
log.add(3, 'this is a 3 by log.add')
log.add(4, 'this is a 4 by log.add')
log.add(5, 'this is a 5 by log.add')
log.add(6, 'this is a 6 by log.add')
log.add(7, 'this is a 7 by log.add')

setTimeout(function () { log.add(5, 'this is a info by async') }, 200)
log.catch(test.testError)('test show')

//add try catch for all test2 modules function and test.start function
log.catchModule(test2);
log.catch(test.start)()
```

### xLog.init()
init reset XLog data

**Kind**: instance method of [XLog](#XLog)

### xLog.size() ⇒ obejct
Get the size of all local log

**Kind**: instance method of [XLog](#XLog)
**Returns**: obejct - - Object {len: 2827, byte: 2903, size: 2.8349609375}

### xLog.get(level) ⇒ object
Get the log data by `level`

**Kind**: instance method of [XLog](#XLog)
**Returns**: object - XLog.data

| Param | Type | Description |
| --- | --- | --- |
| level | number \| string | the level Number or Name String of log item |

### xLog.set(level)
set log level, just show log below level number

**Kind**: instance method of [XLog](#XLog)

| Param | Type | Description |
| --- | --- | --- |
| level | number \| string | the level Number or Name String of log item |

### xLog.show(level, [sort])
Show All XLogs 显示所有日志信息(受限不能大于XLOG.level), 传入level则显示level: 0~number, level name则仅显示name 对应的level

**Kind**: instance method of [XLog](#XLog)

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| level | number \| string | | the level Number or Name String of log item |
| [sort] | string | "'time'" | time or group- show log by time sorted |

**Example**
```js
XLOG.show() print level 0~3 [this.level=3]
XLOG.show(0) print level 0
XLOG.show(1) print level 0-1
XLOG.show(n) print level 0-n, n max is 7
XLOG.show('EMERGENCY') optional ['ALERT','CRITICAL','ERROR','WARN','NOTICE','INFO','LOG'] print corresponding level
```

### xLog.find(str, level)
Show and Print the log info by str or level

**Kind**: instance method of [XLog](#XLog)

| Param | Type | Description |
| --- | --- | --- |
| str | string | find log by str, find log by console, level,stack info, etc... |
| level | number \| string | the level Number or Name String of log item find, if null no level limited |

### xLog.reset(level)
reset log data 重置所有日志内容

**Kind**: instance method of [XLog](#XLog)

| Param | Type | Description |
| --- | --- | --- |
| level | number \| string | the level Number or Name String of log item |

### xLog.catch(f) ⇒ function
decorate function f with try catch wrapper

**Kind**: instance method of [XLog](#XLog)
**Returns**: function - f - return try catch wrappered f

| Param | Type |
| --- | --- |
| f | function |

### xLog.catchModule(m)
decorate every function of module m with try catch wrapper

**Kind**: instance method of [XLog](#XLog)

| Param | Type | Description |
| --- | --- | --- |
| m | object | module with functions |

### XLog.LOG : enum
XLog.LOG.LEVELHE LOG

**Kind**: static enum of [XLog](#XLog)
**Example**
```js
0: 'EMERGENCY', //system unusable
1: 'ALERT', //immediate action required
2: 'CRITICAL', //condition critical
3: 'ERROR', //condition error
4: 'WARN', //condition warning
5: 'NOTICE', //condition normal, but significant
6: 'INFO', //a purely informational message
7: 'LOG' // LOG or debugging information
```

## LOG
XLog - https://github.com/ccjoe/XLog

**Kind**: global variable

Licensed under the MIT license.