log

package
v0.0.0-...-5613f3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 4 Imported by: 88

README

log

Simple golang/glog wrapper to works with contextual logs.

This wrapper only binds glog's Leveled logging to internal logging functions, and in logger to work with contextes. Context and formatter are provided by the caller while initiated. Log do not have any control over the context.

The purpose of this package is to bind the vLeveled log to predifined levels and work with contexts value its provided.

Log levels are defined with respect to VLevel as:

 Fatal   - 0
 Error   - 1
 Warning - 2
 Info    - 3
 Debug   - 4

More Leveled log can be done via V(Level) If Level is lower than Debug level Level will be increased to Debug level.

Simple Usage of Context

 type Context string

 func (c Context) Format() string {
     return "desired format" + string(c)
 }

 l := log.New(Context("hello")))
 l.Infoln("Log Line")

Customized context is available with customized formats.

Available Flags

    -logtostderr=false
		Logs are written to standard error instead of to files.
	-alsologtostderr=false
		Logs are written to standard error as well as to files.
	-log_dir=""
		Log files will be written to this directory instead of the
		default temporary directory.

	Other flags provide aids to debugging.

	-log_backtrace_at=""
		When set to a file and line number holding a logging statement,
		such as
	-log_backtrace_at=gopherflakes.go:234
		a stack trace will be written to the Info log whenever execution
		hits that statement. (Unlike with -vmodule, the ".go" must be
		present.)
	-v=0
		Enable V-leveled logging at the specified level.
	-vmodule=""
		The syntax of the argument is a comma-separated list of pattern=N,
		where pattern is a literal file name (minus the ".go" suffix) or
		"glob" pattern and N is a V level. For instance,
	-vmodule=gopher*=3
		sets the V level to 3 in all Go files whose names begin "gopher".
    
    
    
    IMPORTANT: Setting -stderrthreshold flag can cause no logging as our main goal is to level
               log upon Vlevel instead of severity.
    
    -stderrthreshold=INFO
    		Log events at or above this severity are logged to standard
    		error as well as to files.    	

Run Benchmark

go test -bench=.

Documentation

Index

Constants

View Source
const (
	LevelDebug glog.Level = 4
)

Level specifies a level of verbosity for V logs. The -v flag is of type Level and should be modified only through the flag.Value interface. These constants identify the log levels in order.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Debugln

func Debugln(args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalln

func Fatalln(args ...interface{})

func Flush

func Flush()

Flush flushes all pending log I/O.

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func Warning

func Warning(args ...interface{})

func Warningf

func Warningf(format string, args ...interface{})

func Warningln

func Warningln(args ...interface{})

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Type logger enables logging with context with glog

func New

func New(c gtx.Context) *Logger

New creates an context logger instance which opens access to logging methods. It accepts interface context to format the values as defined

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

func (*Logger) Debugln

func (l *Logger) Debugln(args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

func (*Logger) Errorln

func (l *Logger) Errorln(args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...interface{})

func (*Logger) Flush

func (l *Logger) Flush()

Flush flushes all pending log I/O.

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

func (*Logger) Infoln

func (l *Logger) Infoln(args ...interface{})

func (*Logger) Warning

func (l *Logger) Warning(args ...interface{})

func (*Logger) Warningf

func (l *Logger) Warningf(format string, args ...interface{})

func (*Logger) Warningln

func (l *Logger) Warningln(args ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL