Categorygithub.com/chinglinwen/log
modulepackage
0.0.0-20180802093412-402fdc33bf76
Repository: https://github.com/chinglinwen/log.git
Documentation: pkg.go.dev

# README

log

log package from upspin. ( by the same Golang authors )

Usage

Default level

Info

use flag or environment variable to set different default level through init.

call log.SetLevel("debug") to change level.

Log

log.Print...
log.Debug.Print...

Where info ( added a extra function to the original log package )

Where function usage example:

log.Printf("%v some error info here\n", log.Where())

Log file setting ( size, rotate, etc. )

See http://github.com/natefinch/lumberjack

log.SetOutput(&lumberjack.Logger{
    Filename:   "/var/log/myapp/foo.log",
    MaxSize:    500, // megabytes
    MaxBackups: 3,
    MaxAge:     28, //days
})

Example code to support turn on debug output on the fly

See doc/support-debug-on-the-fly

Other packages considered (but not choose it)

(for the record here only, use above one )

Reference article about log

I believe that there are only two things you should log:

  • Things that developers care about when they are developing or debugging software.
  • Things that users care about when using your software.

Obviously these are debug and info levels, respectively.

https://dave.cheney.net/2015/11/05/lets-talk-about-logging

# Packages

Example of turn debug on the fly $ kill -s SIGUSR1 prog.

# Functions

At returns whether the level will be logged currently.
Fatal writes a message to the log and aborts.
Fatalf writes a formatted message to the log and aborts.
Flush flushes the external logger, if any.
GetLevel returns the current logging level.
Print writes a message to the log.
Printf writes a formatted message to the log.
Println writes a line to the log.
Register connects an ExternalLogger to the default logger.
SetLevel sets the current level of logging.
SetOutput sets the default loggers to write to w.
Where get file location and line number info.

# Constants

Different levels of logging.
Different levels of logging.
Different levels of logging.
Different levels of logging.

# Variables

The set of default loggers for each log level.
The set of default loggers for each log level.
The set of default loggers for each log level.

# Interfaces

ExternalLogger describes a service that processes logs.
Logger is the interface for logging messages.

# Type aliases

Level represents the level of logging.