code.vegaprotocol.io/vega@v0.79.0/logging/config.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package logging
    17  
    18  // Config contains the configurable items for this package.
    19  type Config struct {
    20  	Environment string  `choice:"dev"                                                                   choice:"custom" long:"env"`
    21  	Custom      *Custom `tomlcp:"This section takes effect only when Environment is set to \"custom\"."`
    22  }
    23  
    24  // Custom contains the custom log config.
    25  type Custom struct {
    26  	Zap        *Zap
    27  	ZapEncoder *ZapEncoder
    28  }
    29  
    30  // Zap configures a ZapConfig.
    31  type Zap struct {
    32  	Level            Level
    33  	Development      bool
    34  	Encoding         string // console or json
    35  	OutputPaths      []string
    36  	ErrorOutputPaths []string
    37  }
    38  
    39  // ZapEncoder configures a ZapEncoderConfig.
    40  type ZapEncoder struct {
    41  	CallerKey      string
    42  	EncodeCaller   string
    43  	EncodeDuration string
    44  	EncodeLevel    string
    45  	EncodeName     string
    46  	EncodeTime     string
    47  	LevelKey       string
    48  	LineEnding     string
    49  	MessageKey     string
    50  	NameKey        string
    51  	TimeKey        string
    52  }
    53  
    54  // NewDefaultConfig creates an instance of the package-specific configuration, given a
    55  // pointer to a logger instance to be used for logging within the package.
    56  func NewDefaultConfig() Config {
    57  	return Config{
    58  		Environment: "dev",
    59  		Custom: &Custom{
    60  			Zap: &Zap{
    61  				Development:      true,
    62  				Encoding:         "console",
    63  				Level:            DebugLevel,
    64  				OutputPaths:      []string{"stdout"},
    65  				ErrorOutputPaths: []string{"stderr"},
    66  			},
    67  			ZapEncoder: &ZapEncoder{
    68  				CallerKey:      "C",
    69  				EncodeCaller:   "short",
    70  				EncodeDuration: "string",
    71  				EncodeLevel:    "capital",
    72  				EncodeName:     "full",
    73  				EncodeTime:     "iso8601",
    74  				LevelKey:       "L",
    75  				LineEnding:     "\n",
    76  				MessageKey:     "M",
    77  				NameKey:        "N",
    78  				TimeKey:        "T",
    79  			},
    80  		},
    81  	}
    82  }