tick-core-logger——日志记录和日志切割组件
介绍
对 winston 的封装,tick-core-http-server集成了tick-core-logger
快速开始
npm install @tick-core/logger
import { Logger } from '@tick-core/logger'
const logger = new Logger(logPath: string, isLocal?: boolean)
参数 |
描述 |
logPath |
日志存储位置 |
isLocal |
是否是本地开发 |
⚠️️注意:
isLocal
为true
时所有日志级别都会打印,否则只打印accss log,默认为false
。
API
日志记录
const { error, info } = logger.getLogger(logType: string)
error(tid: string, error: Record<string, any> | string, data?: Record<string, any>)
info(tid: string, data: Record<string, any>)
const { access, app, appError } = logger.getAppLogger()
access(data: string)
app({
tid?: string,
requestTime?: string,
responseTime?: string,
pid?: number,
method?: string,
url?: string,
status?: number,
ms?: number,
data?: {
query?: Record<string, any>,
body?: Record<string, any>,
params?: Record<string, any>,
user?: Record<string, any>,
ip?: string,
},
})
appError(tid: string, error: Error)
函数名 |
描述 |
error |
普通错误日志 |
info |
普通信息日志 |
access |
进程日志 |
app |
http请求日志 |
appError |
http请求失败日志(http code 不等于200) |
参数名 |
描述 |
logType |
日志类型 |
tid |
请求id |
error |
错误信息描述 |
data |
日志消息 |
requestTime |
请求时间 |
responseTime |
响应时间 |
pid |
进程id |
method |
方法 |
url |
请求uil |
status |
http status code |
ms |
请求到响应的时间差 |
query |
query参数 |
body |
body参数 |
params |
params参数 |
user |
user 信息 |
ip |
ip |