Documentation
¶
Overview ¶
Package logit provides an easy way to use foundation for your logging operations.
1. The basic usage:
// Log messages with four levels. // Notice that the default level is info, so first line of debug message // will not be logged! If you want to change level, see logit.ChangeLevelTo logit.Debug("I am a debug message! But I will not be logged in default level!") logit.Info("I am an info message!") logit.Warning("I am a warning message!") logit.Error("I am an error message!") // Also, you can create a new independent Logger to use. See logit.NewLogger. // If you want format your message, just add arguments! logit.Info("format info message! id = %d, content = %s", 1, "info!")
2. logger:
// NewStdoutLogger creates a new Logger holder to standard output, generally a terminal or a console. logger := logit.NewStdoutLogger(logit.DebugLevel) // Then you will be easy to log! logger.Debug("this is a debug message!") logger.Info("this is a info message!") logger.Warning("this is a warning message!") logger.Error("this is a error message!") // NewLogger creates a new Logger holder. // The first parameter "os.Stdout" is a writer for logging. // As you know, file also can be written, just replace "os.Stdout" with your file! // The second parameter "logit.DebugLevel" is the level of this Logger. logger = logit.NewLogger(os.Stdout, logit.DebugLevel) // If you want format your message, just add arguments! logger.Info("format info message! id = %d, content = %s", 1, "info!")
3. enable or disable:
// Every new Logger is running. logger := logit.NewLogger(os.Stdout, logit.DebugLevel) logger.Info("I am running!") // Shutdown the Logger. // So the info message next line will not be logged! logger.Disable() logger.Info("I will not be logged!") // Enable the Logger. // The info message next line will be logged again! logger.Enable() logger.Info("I am running again!")
4. change log level:
logit.Debug("Default log level is info, so debug message will not be logged!") // Change log level to debug level. logit.ChangeLevelTo(logit.DebugLevel) logit.Debug("Now debug message will be logged!")
Index ¶
- Constants
- func ChangeLevelTo(level LogLevel)
- func Debug(msg string, args ...interface{})
- func Disable()
- func Enable()
- func Error(msg string, args ...interface{})
- func Info(msg string, args ...interface{})
- func Warning(msg string, args ...interface{})
- type LogLevel
- type Logger
- func (l *Logger) ChangeLevelTo(newLevel LogLevel)
- func (l *Logger) Debug(msg string, args ...interface{})
- func (l *Logger) Disable()
- func (l *Logger) Enable()
- func (l *Logger) Error(msg string, args ...interface{})
- func (l *Logger) Info(msg string, args ...interface{})
- func (l *Logger) Warning(msg string, args ...interface{})
Constants ¶
const Version = "0.0.3"
Version is the version string representation of the "logit" package.
Variables ¶
This section is empty.
Functions ¶
func ChangeLevelTo ¶ added in v0.0.2
func ChangeLevelTo(level LogLevel)
ChangeLevelTo will change the level of logit to newLevel.
func Debug ¶ added in v0.0.2
func Debug(msg string, args ...interface{})
Debug will output msg as a debug message.
func Error ¶ added in v0.0.2
func Error(msg string, args ...interface{})
Error will output msg as an error message.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a struct based on "log.Logger".
func NewLogger ¶
NewLogger create one Logger with given out and level. The first parameter out is a writer for logging. The second parameter level is the level of this Logger. It returns a new running Logger holder.
func NewStdoutLogger ¶ added in v0.0.2
NewStdoutLogger returns a Logger holder with given log level.
func (*Logger) ChangeLevelTo ¶ added in v0.0.2
ChangeLevelTo will change the level of current Logger to newLevel.