log

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

GCP + Zap Logger

Simple wrapper around zap logger with a few extra niceties for GCP logging.

Example

Simple example with multiple outputs and formats.

package main

import (
	"errors"

	log "github.com/CalculatedSystems/gzlog"
)

func init() {
	if err := log.Init(
		log.WithLevel("ERROR"),                  // set level to only ERRORS
		log.WithLogFile("/tmp/errors-only.log"), // write default output format (console) to file
		log.WithLevel("INFO"),                   // change level to INFO for subsequent options
		log.WithGCPMapping(),                    // change prefixs to match GCP logging style
		log.WithStdOut("JSON"),                  // write to stdout using JSON format
	); err != nil {
		panic(err)
	}
}

func main() {
	// writes to STDOUT only
	log.Info("giving you information")

	// support for standard library log.Print functions
	log.Println("calling Println")

	// error out to both outputs
	err := errors.New("unexpected EOF")
	log.Errorf("error during processing: %v", err)

	// writes to STDOUT and file
	log.DPanic("failure!")
}

Console Output

{"level":"INFO","ts":"2023-03-09T13:18:42.879-0500","msg":"giving you information"}
{"level":"INFO","ts":"2023-03-09T13:18:42.880-0500","msg":"calling Println"}
{"level":"ERROR","ts":"2023-03-09T13:18:42.880-0500","msg":"error during processing: unexpected EOF"}
{"level":"CRITICAL","ts":"2023-03-09T13:18:42.880-0500","msg":"failure!"}

Logfile Contents

2023-03-09T13:18:42.880-0500	error	error during processing: unexpected EOF
2023-03-09T13:18:42.880-0500	dpanic	failure!

Notice how the logfile shows dpanic while the console output displays CRITICAL.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DPanic

func DPanic(args ...any)

DPanic wraps the underlying configured loggers DPanic function

func DPanicf

func DPanicf(template string, args ...any)

DPanicf wraps the underlying configured loggers DPanicf function

func DPanicln

func DPanicln(args ...any)

DPanicln wraps the underlying configured loggers DPanicln function

func DPanicw

func DPanicw(msg string, keysAndValues ...any)

DPanicw wraps the underlying configured loggers DPanicw function

func Debug

func Debug(args ...any)

Debug wraps the underlying configured loggers Debug function

func Debugf

func Debugf(template string, args ...any)

Debugf wraps the underlying configured loggers Debugf function

func Debugln

func Debugln(args ...any)

Debugln wraps the underlying configured loggers Debugln function

func Debugw

func Debugw(msg string, keysAndValues ...any)

Debugw wraps the underlying configured loggers Debugw function

func Error

func Error(args ...any)

Error wraps the underlying configured loggers Error function

func Errorf

func Errorf(template string, args ...any)

Errorf wraps the underlying configured loggers Errorf function

func Errorln

func Errorln(args ...any)

Errorln wraps the underlying configured loggers Errorln function

func Errorw

func Errorw(msg string, keysAndValues ...any)

Errorw wraps the underlying configured loggers Errorw function

func Fatal

func Fatal(args ...any)

func Fatalf

func Fatalf(template string, args ...any)

Fatalf wraps the underlying configured loggers Fatalf function

func Fatalln

func Fatalln(args ...any)

Fatalln wraps the underlying configured loggers Fatalln function

func Fatalw

func Fatalw(msg string, keysAndValues ...any)

Fatalw wraps the underlying configured loggers Fatalw function

func Info

func Info(args ...any)

Info wraps the underlying configured loggers Info function

func Infof

func Infof(template string, args ...any)

Infof wraps the underlying configured loggers Infof function

func Infoln

func Infoln(args ...any)

Infoln wraps the underlying configured loggers Infoln function

func Infow

func Infow(msg string, keysAndValues ...any)

Infow wraps the underlying configured loggers Infow function

func Init

func Init(opts ...setupOpt) (err error)

Init modifies the global logger based on options provided. Errors on any issue provided by options

func Logger

func Logger() *zap.SugaredLogger

func Panic

func Panic(args ...any)

Panic wraps the underlying configured loggers Panic function

func Panicf

func Panicf(template string, args ...any)

Panicf wraps the underlying configured loggers Panicf function

func Panicln

func Panicln(args ...any)

Panicln wraps the underlying configured loggers Panicln function

func Panicw

func Panicw(msg string, keysAndValues ...any)

Panicw wraps the underlying configured loggers Panicw function

func Print

func Print(args ...any)

Print wraps the underlying configured loggers Info function

func Printf

func Printf(template string, args ...any)

Printf wraps the underlying configured loggers Infof function

func Println

func Println(args ...any)

Println wraps the underlying configured loggers Infoln function

func Printw

func Printw(msg string, keysAndValues ...any)

Printw wraps the underlying configured loggers Infow function

func Warn

func Warn(args ...any)

Warn wraps the underlying configured loggers Warn function

func Warnf

func Warnf(template string, args ...any)

Warnf wraps the underlying configured loggers Warnf function

func Warnln

func Warnln(args ...any)

Warnln wraps the underlying configured loggers Warnln function

func Warnw

func Warnw(msg string, keysAndValues ...any)

Warnw wraps the underlying configured loggers Warnw function

func WithGCPMapping

func WithGCPMapping() setupOpt

func WithLevel

func WithLevel(level string) setupOpt

func WithLogFile

func WithLogFile(filename string) setupOpt

func WithStdOut

func WithStdOut(encoding string) setupOpt

func Writer

func Writer() io.Writer

Writer returns the internal `zap.Logger` writer

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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