github.com/skeptycal/errorlogger (go): Package errorlogger implements error logging to a variety of output formats. The goal of this package is to provide a simple and efficient mechanism for managing, testing, debugging, and changing options for error logging throughout a program.  It is a drop-in replacement for the standard library log package and the popular Logrus package.  Code like this works as expected without any changes:  A global logger with a default logging function is supplied:  using the variable 'log' matches most code using the standard library 'log' package or Logrus package.  The default global error logging function is supplied.  Err wraps errors, adds custom messages, formats errors, and outputs messages to the correct io.Writer as specified in the options.  Calling this function will perform all package-level logging and error wrapping. It will then return the error otherwise unchanged and ready to propagate up.  If you do not intend to use any options or disable the logger, it may be more convenient to use only the function alias to call the most common method, Err(), like this:  then, just call the function within error blocks:  or  or even this  if the error does not need to be propagated (bubbled) up. (This is not generally recommended.)  file open  get environment variable  check return value while returning an error  The global defaults may be aliased if there is a concern about name collisions:  By default, logging is enabled and ANSI colorized text is sent to stderr of the TTY. If it is changed and you wish to return to the default text formatter, use  Logging can also be redirected to a file or any io.Writer  To create a new logger with default behaviors, use:  and start logging!  (The defaults are output to os.Stderr, ANSI color, include timestamps, logging enabled, default log level(INFO), no error wrapping, default log function, and use default Logrus logger as pass-through.)  If you want to customize the logger, use:  Some additional features of this package include:  - easy configuration of numerous third party formatters.  - Set log level - the verbosity of the logging may be adjusted. Allowed values are Panic, Fatal, Error, Warn, Info, Debug, Trace. The default is "Info"  Error logging may be disabled during performance critical operations:  In this case, the error function is replaced with a noop function. This removed any enabled/disabled check and usually results in a performance gain when compared to checking a flag during every possible operation that may request logging.  Logging is deferred or reenabled with  This may be done at any time and as often as desired.  - SetLoggerFunc allows setting of a custom logger function. The default is log.Error(), which is compatible with the standard library log package and logrus.  - SetErrorWrap allows ErrorLogger to wrap errors in a specified custom type for use with errors.Is():  For example, if you want all errors returned to be considered type *os.PathError, use:  To wrap all errors in a custom type, use:
Keywords: golang|logger|logging|logging-library|logrus|logrus-go