Documentation
¶
Overview ¶
Package logx provides a wrapped standard output device like printf but with colored enhancements.
Index ¶
- func Colored(clr Color, format string, args ...interface{})
- func ColoredV(clr Color, format string, args ...interface{})
- func CountOfVerbose() int
- func Dim(format string, args ...interface{})
- func DimV(format string, args ...interface{})
- func Error(format string, args ...interface{})
- func Fatal(format string, args ...interface{})
- func Hilight(format string, args ...interface{})
- func IsVerboseMode() bool
- func LazyInit()
- func Log(format string, args ...interface{})
- func Text(format string, args ...interface{})
- func ToColor(clr Color, format string, args ...interface{}) (str string)
- func ToDim(format string, args ...interface{}) (str string)
- func Trace(format string, args ...interface{})
- func Verbose(format string, args ...interface{})
- func Warn(format string, args ...interface{})
- type Color
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Colored ¶
Colored outputs formatted message to stdout while logger level less than log.WarnLevel. For log.SetLevel(log.ErrorLevel), the text will be discarded.
func ColoredV ¶
ColoredV outputs formatted message to stdout while logger level less than log.WarnLevel and cmdr is in VERBOSE mode.
func CountOfVerbose ¶
func CountOfVerbose() int
func Dim ¶
func Dim(format string, args ...interface{})
Dim outputs formatted message to stdout while logger level less than log.WarnLevel.
For example, after log.SetLevel(log.ErrorLevel), the text via Dim will be discarded.
func DimV ¶
func DimV(format string, args ...interface{})
DimV outputs formatted message to stdout while logger level less than log.WarnLevel and cmdr is in verbose mode.
For example, after log.SetLevel(log.ErrorLevel), the text via DimV will be discarded.
While env-var VERBOSE=1, the text via DimV will be shown.
func Error ¶
func Error(format string, args ...interface{})
Error outputs formatted message to stderr.
func Fatal ¶
func Fatal(format string, args ...interface{})
Fatal outputs formatted message to stderr.
func Hilight ¶
func Hilight(format string, args ...interface{})
Hilight outputs formatted message to stdout while logger level less than log.WarnLevel. For log.SetLevel(log.ErrorLevel), the text will be discarded.
func IsVerboseMode ¶
func IsVerboseMode() bool
func LazyInit ¶
func LazyInit()
LazyInit initials local lx instance properly. While you are storing a log.Logger copy locally, DO NOT put these codes into func init() since it's too early to get a unconfigurec log.Logger.
The best time to call LazyInit is at cmdr.Root(...).AddGlobalPreAction(...)
root := cmdr.Root(appName, version). AddGlobalPreAction(func(cmd *cmdr.Command, args []string) (err error) { logx.LazyInit() })
For this usage, refer to: https://github.com/hedzr/bgo/blob/master/cli/bgo/cmd/root_cmd.go#L31
func Log ¶
func Log(format string, args ...interface{})
Log will print the formatted message to stdout.
While the message ends with '\n', it will be printed by print(), so you'll see it always. But if not, the message will be printed by hedzr/log. In this case, its outputting depends on hedzr/log.GetLogLevel() >= log.DebugLevel.
Log outputs formatted message to stdout while logger level less than log.WarnLevel. For log.SetLevel(log.ErrorLevel), the text will be discarded.
func Text ¶
func Text(format string, args ...interface{})
Text prints formatted message without any predefined ansi escaping.
func Trace ¶
func Trace(format string, args ...interface{})
Trace outputs formatted message to stdout while logger level is log.TraceLevel, or cmdr is in TRACE mode or trace module is enabled.
Types ¶
type Color ¶
type Color int
const ( Black Color = 30 Red Color = 31 Green Color = 32 Yellow Color = 33 Blue Color = 34 Magenta Color = 35 Cyan Color = 36 LightGray Color = 37 DarkGray Color = 90 LightRed Color = 91 LightGreen Color = 92 LightYellow Color = 93 LightBlue Color = 94 LightMagenta Color = 95 LightCyan Color = 96 White Color = 97 BgNormal Color = 0 BgBoldOrBright Color = 1 BgDim Color = 2 BgUnderline Color = 4 BgUlink Color = 5 BgHidden Color = 8 DarkColor = LightGray )