log

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: Unlicense Imports: 9 Imported by: 117

Documentation

Overview

Package log contains necessary logging functions

Index

Examples

Constants

View Source
const (
	ERROR = iota
	INFO  = iota
	DEBUG = iota
)

Logging level

View Source
const (
	Ldate = 1 << iota
	Ltime
	Lmicroseconds
	Llongfile
	Lshortfile
	LUTC
	Lmsgprefix
	LstdFlags = Ldate | Ltime
)

These constants are the same as in the standard package "log".

See the output of:

go doc log.Ldate

Variables

This section is empty.

Functions

func Debug

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

Debug writes to debug log

func Error

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

Error writes to error log

func Fatal

func Fatal(args ...interface{})

Fatal writes to error log and exits application

func Fatalf

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

Fatalf writes to error log and exits application

func GetLevel added in v0.1.3

func GetLevel() int

GetLevel returns logLevel

func Info

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

Info writes to info log

func LogPanic added in v0.6.0

func LogPanic(prefix string)

LogPanic is a convinient deferred helper function to log a panic in a goroutine. It should not be used where proper error handling is required.

Example
package main

import (
	"os"

	"github.com/AdguardTeam/golibs/log"
)

func main() {
	log.SetOutput(os.Stdout)
	log.SetFlags(0)

	f := func() {
		defer log.LogPanic("")

		panic("fail")
	}

	f()

	f = func() {
		defer log.LogPanic("f")

		panic("fail")
	}

	f()

}
Output:


[error] recovered from panic: fail
[error] f: recovered from panic: fail

func Print

func Print(args ...interface{})

Print writes to info log

func Printf

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

Printf writes to info log

func Println

func Println(args ...interface{})

Println writes to info log

func SetFlags added in v0.5.0

func SetFlags(flags int)

SetFlags sets the output flags for the default logger. The flag bits are Ldate, Ltime, and so on.

func SetLevel

func SetLevel(level int)

SetLevel sets logging level

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets output printing method

func StdLog added in v0.4.4

func StdLog(prefix string, level int) (std *log.Logger)

StdLog returns a Go standard library logger that writes everything to logs the way this library's logger would. This is useful for cases that require a stdlib logger, for example http.Server.ErrorLog.

func Tracef

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

Tracef writes to debug log and adds the calling function's name

func Writer added in v0.4.3

func Writer() io.Writer

Writer returns the output destination for the default logger.

Types

type Timer added in v0.1.2

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

Timer is a wrapper for time

func StartTimer added in v0.1.2

func StartTimer() Timer

StartTimer returns a Timer with a start time

func (*Timer) LogElapsed added in v0.1.2

func (t *Timer) LogElapsed(message string, args ...interface{})

LogElapsed writes to log message and elapsed time

Jump to

Keyboard shortcuts

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