支持日志编码配置

dev
truthhun 1 year ago
parent 9c648b8374
commit 2662f98059

@ -1,5 +1,7 @@
# 程序运行级别debug、info、warn、error # 程序运行级别debug、info、warn、error
level="debug" level="debug"
# 日志编码方式支持json、console
logEncoding="console"
port="8080" port="8080"
[database] [database]
driver="mysql" driver="mysql"

@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
@ -103,17 +103,21 @@ func initConfig() {
fmt.Println("viper.Unmarshal", err) fmt.Println("viper.Unmarshal", err)
} }
initLogger(cfg.Level) initLogger(cfg.Level, cfg.LogEncoding)
cfg.Database.Prefix = "mnt_" cfg.Database.Prefix = "mnt_"
logger.Info("config", zap.Any("config", cfg)) logger.Info("config", zap.Any("config", cfg))
} }
func initLogger(level string, paths ...string) { func initLogger(level, LogEncoding string, paths ...string) {
var err error var err error
cfg := zap.NewProductionConfig() cfg := zap.NewProductionConfig()
cfg.Encoding = "console"
if LogEncoding != "console" {
cfg.Encoding = "json"
}
cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
lv := zap.InfoLevel lv := zap.InfoLevel

@ -2,10 +2,11 @@ package conf
// Config app config // Config app config
type Config struct { type Config struct {
Level string // Level string //
Port int // listent port LogEncoding string // log encoding, json or console
Database Database Port int // listent port
JWT JWT Database Database
JWT JWT
} }
type Database struct { type Database struct {

@ -63,7 +63,7 @@
> >
<el-button <el-button
style="float: right; padding: 3px 0" style="float: right; padding: 3px 0"
icon="el-icon-refresh" icon="el-icon-tickets"
type="text" type="text"
> >
依赖安装教程</el-button 依赖安装教程</el-button

Loading…
Cancel
Save