支持日志编码配置

dev
truthhun 1 year ago
parent 9c648b8374
commit 2662f98059

@ -1,5 +1,7 @@
# 程序运行级别debug、info、warn、error
level="debug"
# 日志编码方式支持json、console
logEncoding="console"
port="8080"
[database]
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 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
distributed under the License is distributed on an "AS IS" BASIS,
@ -103,17 +103,21 @@ func initConfig() {
fmt.Println("viper.Unmarshal", err)
}
initLogger(cfg.Level)
initLogger(cfg.Level, cfg.LogEncoding)
cfg.Database.Prefix = "mnt_"
logger.Info("config", zap.Any("config", cfg))
}
func initLogger(level string, paths ...string) {
func initLogger(level, LogEncoding string, paths ...string) {
var err error
cfg := zap.NewProductionConfig()
cfg.Encoding = "console"
if LogEncoding != "console" {
cfg.Encoding = "json"
}
cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
lv := zap.InfoLevel

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

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

Loading…
Cancel
Save