package
5.0.0+incompatible
Repository: https://github.com/hpe-storage/common-host-libs.git
Documentation: pkg.go.dev

# README

Logger, helper around logrus

A Helper around Logrus to provide additional functionality as below:

  1. Initializer to set default log level, log location etc
  2. Initializer to automatically add hooks for stdout and file
  3. Supports log rotation with max_size and max_file params
  4. Allow command line overrides using flag

Howto use it

import(
    log "github.com/hpe-storage/common-host-libs/logger"
)

// Example1:
// initialize with nil params to consider default values
func main() {
    log.InitLogging("/var/log/hpe-storage.log", nil, false)

    // ### Use logrus as normal
    log.WithFields(log.Fields{
    "provisioner": "doryd",
    }).Error("error appears here")
}

// Example2:
// initialize with overriding log_level to debug: default(info)
func main() {
    log.InitLogging("/var/log/hpe-storage.log", &log.LogParams{Level: "debug"}, false)
    // ### Use logrus as normal
    log.WithFields(log.Fields{
    "provisioner": "doryd",
    }).Debug("debug appears here")
}


// Example3:
// initialize with logging to both file and stdout/stderr
func main() {
    log.InitLogging("/var/log/hpe-storage.log", nil, true)
    // ### Use logrus as normal
    log.WithFields(log.Fields{
    "provisioner": "doryd",
    }).Error("error appears here")
}


// Example4:
// initialize with log format as json: default(text)
func main() {
    log.InitLogging("/var/log/hpe-storage.log", &log.LogParams{Format: "json"}, false)
    // ### Use logrus as normal
    log.WithFields(log.Fields{
    "provisioner": "doryd",
    }).Error("error appears here")
}

// Example5:
// initialize with log level as trace using env params
func main() {
    os.Setenv("LOG_LEVEL", "trace")
    log.InitLogging("/var/log/hpe-storage.log", nil, false)
    // ### Use logrus as normal
    log.WithFields(log.Fields{
    "provisioner": "doryd",
    }).Trace("trace appears here")
}

# Functions

No description provided by the author
No description provided by the author
AddHook adds a hook to the standard logger hooks.
No description provided by the author
Debug logs a message at level Debug on the standard logger.
Debugf logs a message at level Debug on the standard logger.
Debugln logs a message at level Debug on the standard logger.
Error logs a message at level Error on the standard logger.
Errorf logs a message at level Error on the standard logger.
Errorln logs a message at level Error on the standard logger.
Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
GetLevel returns the standard logger level.
HTTPLogger : wrapper for http logging.
Info logs a message at level Info on the standard logger.
Infof logs a message at level Info on the standard logger.
Infoln logs a message at level Info on the standard logger.
Initialize logging with given params.
IsLevelEnabled checks if the log level of the standard logger is greater than the level param.
IsSensitive checks if the given key exists in the list of bad words (sensitive info).
MapScrubber checks if the map contains any sensitive information like username/password/secret If found, then masks values for those keys, else copies the original value and returns new map.
NewConsoleHook creates a new log hook for writing to stdout/stderr.
NewFileHook creates a new log hook for writing to a file.
Panic logs a message at level Panic on the standard logger.
Panicf logs a message at level Panic on the standard logger.
Panicln logs a message at level Panic on the standard logger.
Print logs a message at level Info on the standard logger.
Printf logs a message at level Info on the standard logger.
Println logs a message at level Info on the standard logger.
Scrubber checks if the args list contains any sensitive information like username/password/secret If found, then returns masked string list, else returns the original input list unmodified.
Trace logs a message at level Trace on the standard logger.
Tracef logs a message at level Trace on the standard logger.
Traceln logs a message at level Trace on the standard logger.
Warn logs a message at level Warn on the standard logger.
Warnf logs a message at level Warn on the standard logger.
Warning logs a message at level Warn on the standard logger.
Warningf logs a message at level Warn on the standard logger.
Warningln logs a message at level Warn on the standard logger.
Warnln logs a message at level Warn on the standard logger.
WithContext creates an entry from the standard logger and adds a context to it.
WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
WithField creates an entry from the standard logger and adds a field to it.
WithFields creates an entry from the standard logger and adds multiple fields to it.
WithTime creats an entry from the standard logger and overrides the time of logs generated with it.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
in MB.
No description provided by the author
No description provided by the author
in MB.
No description provided by the author

# Structs

ConsoleHook sends log entries to stdout.
FileHook sends log entries to a file.
LogParams to configure logging.

# Type aliases

No description provided by the author