Go to file
Charles Iliya Krempeaux 1665d92ed6 renaming from "package flog" to "package log" 2022-06-29 16:56:57 -07:00
LICENSE initial commit. this is still a work in progress. 2015-10-10 00:29:18 -07:00
README.md renaming from "package flog" to "package log" 2022-06-29 16:56:57 -07:00
calltrace.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
context.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
context_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
copying_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
copying_router_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
default.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
default_writing_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
default_writing_router_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
discarding_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
discarding_router_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
doc.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
error_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
errors.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
fanout_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
fanout_router_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
filtering_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
filtering_router_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
flogger.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_debug.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_error.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_fatal.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_panic.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_print.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_trace.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_warn.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_with.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_flogger_with_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_alert.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_alert_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_begin.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_debug.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_debug_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_end.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_error.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_error_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_fatal.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_highlight.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_highlight_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_inform.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_inform_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_mute.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_panic.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_prefix.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_prefix_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_trace.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_trace_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_unmute.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_warn.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
internal_logger_warn_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
logger.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
logger_test.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
mapping_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
non_blocking_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
pretty_writing_router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00
router.go renaming from "package flog" to "package log" 2022-06-29 06:56:41 -07:00

README.md

go-log

A library that provides structured and formatted logging for the Go programming language.

(This Go package was originally named flog, but in version 2 was renamed to log.)

Online Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-log

GoDoc

Basic Usage

Basic usage of this logger looks like this:

router := log.NewPrettyWritingRouter(os.Stdout)

logger := log.New(router)

Once you have the logger, you can do things such as:

logger.Print("Hello world!")
logger.Println("Hello world!")
logger.Printf("Hello %s!", name)

logger.Panic("Uh oh!")
logger.Panicln("Uh oh!")
logger.Panicf("Uh oh, had a problem happen: %s.", problemDescription)

logger.Fatal("Something really bad happened!")
logger.Fatalln("Something really bad happened!")
logger.Fatalf("Something really bad happened: %s.", problemDescription)

BTW, if the PrettyWritingRouter was being used, then this:

logger.Print("Hello world!")

Would generate output like the following:

Hello world!	(2015-10-10 17:28:49.397356044 -0700 PDT)

(Although note that in actual usage this would have color.)

(Note that for for other routers the actual output would look very different! What the output looks like is router dependent.)

Structured Logging

But those method calls all generated unstructure data.

To include structured data the logger's With method needs to be used. For example:

newLogger := logger.With(map[string]interface{}{
	"method":"Toil",
	"secret_note":"Hi there! How are you?",
})

Then if the PrettyWritingRouter was being used, then this:

newLogger.Print("Hello world!")

Would generate output like the following:

Hello world!	(2015-10-10 17:28:49.397356044 -0700 PDT)	method="Toil"	secret_note="Hi there! How are you?"

(Again, note that in actual usage this would have color.)

Deployment Environment

Of course in a real application system you should (probably) create a different kind of logger for each deployment environment.

Even though the PrettyWritingRouter is great for a development deployment environment (i.e., "DEV") it is probably not appropriate for a production deployment environment (i.e., "PROD").

For example:

var logger log.Logger

switch deploymentEnvironment {
case "DEV":
	router := log.NewPrettyWritingRouter(os.Stdout)
	
	logger = log.New(router)
case "PROD":
	verboseRouter = log.NewDiscardingRouter()
	if isVerboseMode {
		verboseRouter = NewCustomVerboseRouter()
	}
	
	panicDetectionRouter := log.NewFilteringRouter(NewCustomerPanicRecordingRouter(), filterOnlyPanicsFunc)
	
	errorDetectionRouter := log.NewFilteringRouter(NewCustomerPanicRecordingRouter(), filterOnlyErrorsFunc)
	
	router := NewFanoutRouter(verboseRouter, panicDetectionRouter, errorDetectionRouter)
	
	logger = log.New(router)
}