app-lib-log v0.0.54
一、背景介绍
- nodejs 与 js 统一日志打印风格
- 便捷线上与开发的灵活调整
- 彩色高亮打印
二、功能描述
- 支持浏览器与 nodejs
- 支持彩色输出日志
- 支持日志级别设置
- 支持日志收集扩展
三、注意事项
- 类的方法输出 在 md 中不能呈现 在 doc/html 文档中可以
四、使用案列
五、todo 列表
- brower 端支持不打野堆栈的情况输出
- brower 端支持文本转换输出
六、API
Classes
Constants
Functions
ALL_FUNCTIONS
- 日志级别相关方法
级别 | 堆栈 | 调试 | 日志 | 信息 | 成功 | 表格 | 时间 | 警告 | 错误 |
---|---|---|---|---|---|---|---|---|---|
方法名 | trace | debug | log | info | success | table | time | warn/warnNoTrace | error/errorNoTrace |
简写 | t | d | l | i | s | T | tt | w/wn | e/wn |
模块化 | mTrace | mDebug | mLog | mInfo | mSuccess | mTable | mTime | mWarn/mWarnNoTrace | mError/mErrorNoTrace |
简写 | mt | md | ml | mi | ms | mT | mtt | mw/mwn | me/mwn |
- 彩色转换与其他方法
参考详细文档
Kind: global constant
TYPE
日志类型
级别 | 堆栈 | 调试 | 日志 | 信息 | 成功 | 表格 | 时间 | 警告 | 错误 |
---|---|---|---|---|---|---|---|---|---|
常量名称 | TRACE | DEBUG | LOG | INFO | SUCCESS | TABLE | TIME | WARN | ERROR |
常量值 | trace | debug | log | info | success | table | time | warn | error |
Kind: global constant
LEVEL
日志级别
- 通过 setOption({level:number}) 进行打印高于该值 (number) 的日志
- 调整该顺序值进行灵活打印
- 或者只打印某几项日志
级别 | 堆栈 | 调试 | 日志 | 信息 | 成功 | 表格 | 时间 | 警告 | 错误 |
---|---|---|---|---|---|---|---|---|---|
常量名 | trace | debug | log | info | success | table | time | warn | error |
常量值 | 10 | 20 | 30 | 31 | 32 | 33 | 40 | 60 | 70 |
Kind: global constant
option
默认配置
- setOption - 进行设置
- getOption - 获取当前的配置
参数名 | 参数类型 | 参数默认值 | 参数描述 | 备注 | |
---|---|---|---|---|---|
bindGlobalName | string | log | 全局的名称 | 直接在 windows 或者 nodejs 环境中直接使用 log 即可 | |
level | number/array | 20 | 打印日志级别 | 低于该级别的类型忽略输出/或者打印指定级别 'warn',error 的日志 | |
moduleName | string | '' | 模块名称 | 模块打印的名称 | mxx 打印时直接输入自定义名称即可 |
isModule | boolean | false | 是否开启模块标识打印 | 关闭模块打印表示 | |
isColorful | boolean | true | 是否开启彩色打印 | ||
colorful | object | 参考彩色配置 | 不同终端、不同级别颜色配置 | ||
LEVEL | object | 参考 LEVEL | 配置打印级别值 | 灵活调整日志级别顺序 | |
dateFormatter | string/function | 'YYYY-MM-DD HH:mm:ss' | 日期打印格式化输出 | ||
onLogger | function | null | 日志输出记录 | 用于日志的收集管理 |
Kind: global constant
log
- 默认会挂载全局 直接通过 log 来使用
Kind: global constant
setOption(option) ⇒ objcet
设置配置
- 设置后即刻生效
- 后续日志打印按照该设置进行
Kind: global function
Returns: objcet - 新的参数配置 option
Param | Type | Description |
---|---|---|
option | object | 参考默认 option 配置 |
getOption() ⇒ object
获取配置
Kind: global function
Returns: object - 参考默认 option
auotLevel/auotLogLevel() ⇒ object
根据命令行终端参数动态设置日志级别
- --debug
- process.env.DEBUG 仅在 nodejs 中生效 debug 模式 默认级别为 0 否则为 21
Kind: global function
Returns: object - log 日志实例
tb/transTextColorBlock(text, opitons) ⇒ string
输出执行缩进 显示块长度 文件颜色 和背景色的 文本 1. option 参数
- indent 缩进
- width 块的长度
- algin 对齐
- color 颜色
- background 背景颜色
Kind: global function
Returns: string - 彩色文案
Param | Type |
---|---|
text | string |
opitons | object |
tx/transTextColor(text, color, background) ⇒ string
转换文本颜色
Kind: global function
Returns: string - 彩色文案
Param | Type | Description |
---|---|---|
text | string | 文本内容 |
color | string | 文字颜色 hex 格式 |
background | string | 背景颜色 hex 格式 |
txl/transTextColorAndLog(text, color, background) ⇒ string
转换文本颜色并且打印
- 不受级别控制
Kind: global function
Returns: string - 彩色文本内容
Param | Type | Description |
---|---|---|
text | string | 文本内容 |
color | string | 文字颜色 hex 格式 |
background | string | 背景颜色 hex 格式 |
tl/transLevelTextColor(level, text, isBackground) ⇒ string
转换指定级别文本颜色
- 不受级别控制
Kind: global function
Returns: string - 彩色文本内容
Param | Type | Default | Description |
---|---|---|---|
level | string | "TYPE.INFO" | 日志界别 参考 log.TYPE |
text | string | 打印的文本内容 | |
isBackground | boolean | 是否包含背景 |
tll/transLevelTextColorAndLog(level, text, isBackground) ⇒ string
转换指定级别文本颜色
- 不受级别控制
Kind: global function
Returns: string - 彩色文本内容
Param | Type | Default | Description |
---|---|---|---|
level | string | "TYPE.INFO" | 日志界别 参考 log.TYPE |
text | string | 打印的文本内容 | |
isBackground | boolean | 是否包含背景 |
tlh/transLevelHeaderAndLog(level, text, chalkOption) ⇒ string
打印指定的脚本
- 带级别字段和内容
Kind: global function
Returns: string - 转换后的字符内容
Param | Type | Description |
---|---|---|
level | string | 级别 |
text | string | 文本内容 |
chalkOption | string | 颜色配置参数 { bg, color } 形式 |
t/trace(args) ⇒ null
trace 调试打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
d/debug(args) ⇒ null
debug 调试打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
i/info(args) ⇒ null
info 信息打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
l/log(args) ⇒ null
log 日志打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
s/success(args) ⇒ null
success 成功打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
tt/time(args) ⇒ null
time 时间打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
T/table(args) ⇒ null
table 表格打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
w/warn(args) ⇒ null
warn 警告打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
wn/warnNoTrace(args) ⇒ null
debug 调试打印
- 不带堆栈
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
e/error(args) ⇒ null
error 错误打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
en/errorNoTrace(args) ⇒ null
error 调试打印
- 不带堆栈
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
mt/mTrace(args) ⇒ null
mTrace 堆栈打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
md/mDebug(args) ⇒ null
mDebug 调试打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
mi/mInfo(args) ⇒ null
mInfo 信息打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
ml/mLog(args) ⇒ null
mLog 日志打印 (模块化)
- 原生的控制台打印
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
ms/mSuccess(args) ⇒ null
mSuccess 成功打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
mtt/mTime(args) ⇒ null
mTime 调试打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
mT/mTable(args) ⇒ null
mTable 表格打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
mw/mWarn(args) ⇒ null
mWarn 告警打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
mwn/mWarnNoTrace(args) ⇒ null
mWarnNoTrace 调试打印 (模块化)
- 不带堆栈
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
me/mError(args) ⇒ null
mError 调试打印 (模块化)
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
men/mErrorNoTrace(args) ⇒ null
mErrorNoTrace 调试打印 (模块化)
- 不带堆栈
Kind: global function
Param | Type | Description |
---|---|---|
args | any | 打印的内容 |
autoFillText(text, length, aligin) ⇒
autoFillText 动态补全文本
- 常用于打印类似各种级别的日志 配置配合 tl 使用
Kind: global function
Returns: 整合的字段
Param | Type | Default | Description |
---|---|---|---|
text | string | 文本内容 | |
length | number | 长度 默认级别打印的长度设置保持一致 超出长度按照超出的部分显示 | |
aligin | string | "right" | 对齐 支持 center,left 和 默认 right |
fill(length, content) ⇒
- 填充文本 (一般是空白)
Kind: global function
Returns: string 填充后的内容
Param | Type | Description |
---|---|---|
length | number | 填充的次数 |
content | string | 填充的内容 |
create(option) ⇒ object
- 第一次引入 默认创建实例
- 后续导入 直接返回第一次创建的实例
Kind: global function
Returns: object - logInstance 日志实例
Param | Type | Description |
---|---|---|
option | Object | 详细参数参考 option |
七、发布日志
- 2024-12-11 12-00-38-去掉debugger