diff --git a/app.example.toml b/app.example.toml index 0ef9cea..4fc445f 100644 --- a/app.example.toml +++ b/app.example.toml @@ -1,5 +1,7 @@ # 程序运行级别:debug、info、warn、error level="debug" +# 日志编码方式,支持:json、console +logEncoding="console" port="8080" [database] driver="mysql" diff --git a/cmd/root.go b/cmd/root.go index 4101ae3..aa39095 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 diff --git a/conf/config.go b/conf/config.go index 6fe7e92..c069b18 100644 --- a/conf/config.go +++ b/conf/config.go @@ -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 { diff --git a/web/pages/admin/dashboard.vue b/web/pages/admin/dashboard.vue index 0e40e51..02859b9 100644 --- a/web/pages/admin/dashboard.vue +++ b/web/pages/admin/dashboard.vue @@ -63,7 +63,7 @@ > 依赖安装教程