Skip to content

Commit

Permalink
fix: 新增修改日志等级
Browse files Browse the repository at this point in the history
  • Loading branch information
yusheng929 committed Aug 28, 2024
1 parent b026042 commit 8ef7c99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
11 changes: 2 additions & 9 deletions apps/Assistant.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { karin, YamlEditor, config } from 'node-karin'
import { karin } from 'node-karin'
import { 编辑文件 } from '#lib'

export const 黑白名单 = karin.command(/^#(取消)?(拉黑|拉白)(群)?/, async (e) => {
Expand All @@ -16,11 +16,4 @@ export const 黑白名单 = karin.command(/^#(取消)?(拉黑|拉白)(群)?/, as
const targetType = e.msg.includes('群') ? 'Group' : 'User'

return await 编辑文件.编辑黑白名单(e, type, isRemoval, targetType, id)
}, { name: '取消拉黑拉白群', priority: '-1', permission: 'master' })

export const 修改日志等级 = karin.command(/^#(修改|设置)日志等级/, async (e) => {
const 日志等级列表 = ['trace', 'debug', 'info', 'warn', 'fatal', 'mark', 'error', 'off']
const 日志等级 = e.msg.replace(/^#?(设置|修改)日志等级/, '').trim()
if (!日志等级列表.includes(日志等级)) return e.reply('❎ 请输入正确的参数,可选:\ntrace,debug,info,warn,fatal,mark,error,off')
return await 编辑文件.编辑文件(e, 'config.yaml', 日志等级, 'log4jsCfg.level', '日志等级')
}, { name: '修改日志等级', priority: '-1', permission: 'master' })
}, { name: '取消拉黑拉白群', priority: '-1', permission: 'master' })
9 changes: 8 additions & 1 deletion apps/KarinSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const cfgMap = {
黑名单群: 'App_BlackList.groups',
白名单用户: 'App_WhiteList.users',
白名单群: 'App_WhiteList.groups',
日志等级: 'config_log4jsCfg.level',
}

const CfgReg = `^#?(Karin|karin|卡莲)设置\\s*(${lodash.keys(cfgMap).join('|')})?\\s*(.*)$`
Expand All @@ -17,7 +18,13 @@ export const set = karin.command(CfgReg, async (e) => {
if (reg && reg[2]) {
let val = reg[3] || ''
let cfgKey = cfgMap[reg[2]]
if (val.includes('开启') || val.includes('关闭')) {
if (cfgKey == 'config_log4jsCfg.level') {
let level = ['trace', 'debug', 'info', 'warn', 'fatal', 'mark', 'error', 'off']
if (!level.includes(val)) {
e.reply('请输入正确的日志等级,可选:\ntrace,debug,info,warn,fatal,mark,error,off', true)
return true;
}
} else if (val.includes('开启') || val.includes('关闭')) {
val = !/关闭/.test(val)
} else {
cfgKey = ''
Expand Down
18 changes: 17 additions & 1 deletion resources/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>

<div class="cfg-box">
<div class="cfg-group">基础设置</div>
<div class="cfg-group">应用配置</div>
<ul class="cfg-ul">

<li class="cfg-li">
Expand Down Expand Up @@ -53,4 +53,20 @@

</ul>
</div>

<div class="cfg-box">
<div class="cfg-group">通用配置</div>
<ul class="cfg-ul">

<li class="cfg-li">
<div class="cfg-line">
日志等级
<span class="cfg-hint">Karin设置日志等级</span>
{{@log4jsCfg_level}}
</div>
<div class="cfg-desc">日志等级trace, debug, info, warn, fatal, mark, error, off</div>
</li>

</ul>
</div>
{{/block}}

0 comments on commit 8ef7c99

Please sign in to comment.