package
0.0.0-20241105204840-47fcb773a808
Repository: https://github.com/surahman/mcq-platform.git
Documentation: pkg.go.dev

# README

Zap Structured Logging

Configuration loading is designed for containerization in mind. The container engine and orchestrator can mount volumes (secret or regular) as well as set the environment variables as outlined below.

You may set configurations through both files and environment variables. Please note that environment variables will override the settings in the configuration files. The configuration files are all expected to be in YAML format.


Table of contents


Zap Structured Logging

Structured logging is handled through Zap. Please refer to Zap's documentation on how to set the fields below.

Only the BuiltinConfig and BuiltinEncoder settings can be provided through environment variables that override values from the configuration files.


File Location(s)

The configuration loader will search for the configurations in the following order:

LocationDetails
/etc/MCQPlatform.conf/The etc directory is the canonical location for configurations.
$HOME/.MCQPlatform/Configurations can be located in the user's home directory.
./configs/The config folder in the root directory where the application is located.
Environment variablesFinally, the configurations will be loaded from environment variables and override configuration files

Configuration File

The expected file name is LoggerConfig.yaml. All the configuration items below are required.

If specifying settings for the General Config or Encoder Config, all values must be provided.

NameEnvironment Variable KeyTypeDescription
BuiltinConfigLOGGER_BUILTINCONFIGstringMust be one of Development or Production. Required.
BuiltinEncoderConfigLOGGER_BUILTINENCODERCONFIGstringMust be one of Development or Production. Required.
General ConfigNot applicable.General Configurations.Please refer to Zap user documentation.
↳ developmentboolean
↳ disableCallerboolean
↳ disableStacktraceboolean
↳ encodingstring
↳ outputPathsstring array
↳ errorOutputPathsstring array
Encoder ConfigNot applicable.Encoder Configurations.Please refer to Zap user documentation.
↳ messageKeystring
↳ levelKeystring
↳ timeKeystring
↳ nameKeystring
↳ callerKeystring
↳ functionKeystring
↳ stacktraceKeystring
↳ skipLineEndingboolean
↳ lineEndingstring
↳ consoleSeparatorstring

Example Configuration File

builtin_config: Development | Production
builtin_encoder_config: Development | Production
general_config:
  development: boolean
  disableCaller: boolean
  disableStacktrace: boolean
  encoding: string
  outputPaths: [string, array]
  errorOutputPaths: [string, array]
encoder_config:
  messageKey: string
  levelKey: string
  timeKey: string
  nameKey: string
  callerKey: string
  functionKey: string
  stacktraceKey: string
  skipLineEnding: boolean
  lineEnding: string
  consoleSeparator: string

Example Environment Variables

export LOGGER_BUILTINCONFIG="Development"
export LOGGER_BUILTINENCODERCONFIG="Production"

# Functions

NewLogger will create a new uninitialized logger.
NewTestLogger will create a new development logger to be used in test suites.

# Structs

Logger is the Zap logger object.