diff --git a/infra/logger/config.yaml b/conf/log_config.yaml similarity index 100% rename from infra/logger/config.yaml rename to conf/log_config.yaml diff --git a/infra/logger/config.go b/infra/logger/config.go index 6589465..8b5da20 100644 --- a/infra/logger/config.go +++ b/infra/logger/config.go @@ -48,9 +48,9 @@ type outputSettings struct { func InitConfig() error { var err error - viper.SetConfigName("config") + viper.SetConfigName("log_config") viper.SetConfigType("yaml") - viper.AddConfigPath("./") + viper.AddConfigPath("./conf/") if err = viper.ReadInConfig(); err != nil { return err } diff --git a/infra/logger/log_config.yaml b/infra/logger/log_config.yaml new file mode 100644 index 0000000..7f40e25 --- /dev/null +++ b/infra/logger/log_config.yaml @@ -0,0 +1,69 @@ +# 配置输出 支持三种输出 db file 和console +# db为数据库输出 目前支持输出到mongo 配置为map +db: + mongo1: + dbtype: mongo + host: 127.0.0.1 + port: 27017 + database: GAAS_MOM + # mongo的collection + Table: LOG + mongo2: + dbtype: mongo + host: 127.0.0.1 + port: 27017 + database: GAAS_MOM + # mongo的collection + Table: LOG2 + +# file为输出到文件 配置为map 按天分割 +file: + common: + # 文件location + filename: ./log/common.log + # 支持文件的最大个数 + MaxAge: 30 + user: + # 文件location + filename: ./log/user.log + # 支持文件的最大个数 + MaxAge: 7 + +# console 为输出到控制台 +console: + enable: true # bool 是否输出到控制台 + + +# module配置输出源 配置为map +config: + # root为根配置 默认配置 module未配置则使用root配置 + + + root: + # 此处的file、db、console名称可以随意起 见文知意即可 + file: + # drivertype 为驱动类型 file-文件 db-数据库 console-控制台 + drivertype: file + level: debug + # drivername 需要和output的map 键值相同 + drivername: common + db: + drivertype: db + level: debug + drivername: mongo1 + console: + drivertype: console + level: debug + drivername: console + user: + file: + # drivertype 为驱动类型 file-文件 db-数据库 console-控制台 + drivertype: file + level: info + # drivername 需要和output的map 键值相同 + drivername: user + db: + drivertype: db + level: debug + drivername: mongo2 +