Documentation
¶
Overview ¶
The logger package allows for organized, simplified, custom logging for any application. Logger makes creating logs easy. Create multiple loggers for specialized purposes each with their own specific settings such as verbosity, log file location, and whether it's show on stdout, written to file, or only one of them. Logger comes with 4 pre-made logging levels ready for use. There's also a generic Log() function that allows for custom log types.
Logger also has timers that can be attached to logs. This makes it easy to track how long a function or request takes to run. Logger also comes with a wrapper function to check for errors in an application. Instead of having to write out the log to file code for every err if statement, CheckError() will take the error, check if one exists and then write it to the logger of choice. It will also return boolean to tell the calling function if an error happened or not so any custom actions can be performed if needed.
Index ¶
- Constants
- func CheckError(e error, l *Logger) bool
- func GetVerboseLevel() int
- func Verbose(v int)
- type Logger
- func (l *Logger) Close()
- func (l *Logger) Error(format string, v ...interface{})
- func (l *Logger) Fatal(format string, v ...interface{})
- func (l *Logger) File() *Logger
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) Log(eType, color, format string, v ...interface{})
- func (l *Logger) NoFile() *Logger
- func (l *Logger) NoStdout() *Logger
- func (l *Logger) Path(p string) *Logger
- func (l *Logger) Raw() *Logger
- func (l *Logger) StartTimer()
- func (l *Logger) Stdout() *Logger
- func (l *Logger) StopTimer(s string) string
- func (l *Logger) TimeCode(t string) *Logger
- func (l *Logger) Verbose(v int) *Logger
- func (l *Logger) Warning(format string, v ...interface{})
Constants ¶
const ( Reset = "\033[0m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Magenta = "\033[35m" Cyan = "\033[36m" White = "\033[37m" Grey = "\x1B[90m" )
Colors that can be used for Log().
Variables ¶
This section is empty.
Functions ¶
func CheckError ¶
CheckError will check error e and, if not nil, will write the error to the logger l as type Error. CheckError will return a bool value true if there was an error or false if e is nil. CheckError will use the logger with an empty name "" by default if one isn't given.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Type logger is the struct returned and used for logging. The user can set its properties using the associated functions.
func (*Logger) Fatal ¶
Wrapper for Log("Fatal", ...). Shows red in stdout. Exits application with os.Exit(1).
func (*Logger) Log ¶
Log is the core function that will write a log text to file and stdout. The log will be of eType type (used for the filename of the log). In stdout it will be colored color (see const list). The text will use format to Printf v interfaces.
func (*Logger) Raw ¶
Raw tells the logger writer to not pre-include the date. Allows for completely custom log text.
func (*Logger) StartTimer ¶
func (l *Logger) StartTimer()
StartTimer associates a timer with logger l
func (*Logger) StopTimer ¶
StopTimer determines the time elapsed since logger l's timer started and issues an Info level log. The string "{time}" will be replaced with the elapsed time.