From 2662f98059583040d17f16931b95cf1e12b75543 Mon Sep 17 00:00:00 2001 From: truthhun <1272881215@qq.com> Date: Wed, 1 Feb 2023 11:46:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=97=A5=E5=BF=97=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.example.toml | 2 ++ cmd/root.go | 10 +++++++--- conf/config.go | 9 +++++---- web/pages/admin/dashboard.vue | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) 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 @@ > 依赖安装教程