This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/logging/loggerConfig.go
Pradyumna Kaushik 6fb0e4a3fe move cfg to loggers + refactor + log fn wrappers
1. Instead of maintaining a global config, each specialized logger
now stores its config.
2. Refactored logInterface to elektronLogger.
3. Refactored loggerImpl to baseElektronLogger to be consistent with
the rest of the code base.
4. Wrapped elektronLogger#Log(...) and elektronLogf(...) so that we
do not have to use the instance of elektronLogger everytime we want
to log. Instead, we just do logging.Log(...) or logging.Logf(...).
5. Wrapped elektronLogger#WithFields(...) and
elektronLogger#WithField(...).
6. Refactored codebase to adhere to the changes.
2019-12-05 21:32:37 -05:00

65 lines
1.7 KiB
Go

package logging
import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"io/ioutil"
)
type LoggerConfig struct {
SchedTraceConfig struct {
Enabled bool `yaml:"enabled"`
FilenameExtension string `yaml:"filenameExtension"`
AllowOnConsole bool `yaml:"allowOnConsole"`
} `yaml:"schedTrace"`
PCPConfig struct {
Enabled bool `yaml:"enabled"`
FilenameExtension string `yaml:"filenameExtension"`
AllowOnConsole bool `yaml:"allowOnConsole"`
} `yaml:"pcp"`
ConsoleConfig struct {
Enabled bool `yaml:"enabled"`
FilenameExtension string `yaml:"filenameExtension"`
MinLogLevel string `yaml:"minLogLevel"`
AllowOnConsole bool `yaml:"allowOnConsole"`
} `yaml:"console"`
SPSConfig struct {
Enabled bool `yaml:"enabled"`
FilenameExtension string `yaml:"filenameExtension"`
AllowOnConsole bool `yaml:"allowOnConsole"`
} `yaml:"sps"`
TaskDistrConfig struct {
Enabled bool `yaml:"enabled"`
FilenameExtension string `yaml:"filenameExtension"`
AllowOnConsole bool `yaml:"allowOnConsole"`
} `yaml:"clsfnTaskDistrOverhead"`
SchedWindowConfig struct {
Enabled bool `yaml:"enabled"`
FilenameExtension string `yaml:"filenameExtension"`
AllowOnConsole bool `yaml:"allowOnConsole"`
} `yaml:"schedWindow"`
Format []string `yaml:"format"`
}
func GetConfig(logConfigFilename string) (*LoggerConfig, error) {
yamlFile, err := ioutil.ReadFile(logConfigFilename)
if err != nil {
return nil, errors.Wrap(err, "failed to read log config file")
}
c := &LoggerConfig{}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Fatalf("Error in unmarshalling yaml: %v", err)
}
return c, nil
}