logger

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2018 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Copyright (C) 2016-2017 dapperdox.com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	// Error is the error level
	Error = Level(iota)
	// Warn is the warn level
	Warn
	// Info is the info level
	Info
	// Debug is the debug level
	Debug
	// Trace is the trace level
	Trace
)

Variables

View Source
var (
	// Logf is the function called for *f functions
	Logf = log.Printf
	// Logln is the function called for *ln functions
	Logln = log.Println
)
View Source
var DefaultLevel = func() Level {
	if v := strings.ToLower(os.Getenv("LOGLEVEL")); len(v) > 0 {
		for i, j := range LevelString {
			if j == v {
				return i
			}
		}
		log.Fatalf("invalid log level in environment variable LOGLEVEL, expected error|warn|info|debug|trace, got '%s'", v)
	}
	return Info
}()

DefaultLevel is the default log level

View Source
var LevelString = map[Level]string{
	Error: "error",
	Warn:  "warn",
	Info:  "info",
	Debug: "debug",
	Trace: "trace",
}

LevelString is a level to string lookup map

Functions

func Debugf

func Debugf(req *http.Request, format string, args ...interface{})

Debugf logs a message at Debug level

func Debugln

func Debugln(req *http.Request, message ...interface{})

Debugln logs a message at Debug level

func Errorf

func Errorf(req *http.Request, format string, args ...interface{})

Errorf logs a message at Error level

func Errorln

func Errorln(req *http.Request, message ...interface{})

Errorln logs a message at Error level

func Handler

func Handler(h http.Handler) http.Handler

Handler wraps a http.Handler and logs the status code and total response time

func Infof

func Infof(req *http.Request, format string, args ...interface{})

Infof logs a message at Info level

func Infoln

func Infoln(req *http.Request, message ...interface{})

Infoln logs a message at Info level

func Levelf

func Levelf(req *http.Request, level Level, format string, args ...interface{})

Levelf implements log.Printf but includes X-Request-Id and requires a log level

func Levelln

func Levelln(req *http.Request, level Level, message ...interface{})

Levelln implements log.Printf but includes X-Request-Id and requires a log level

func Printf

func Printf(req *http.Request, format string, args ...interface{})

Printf implements log.Printf but includes X-Request-Id

func Println

func Println(req *http.Request, message ...interface{})

Println implements log.Println but includes X-Request-Id

func Tracef

func Tracef(req *http.Request, format string, args ...interface{})

Tracef logs a message at Trace level

func Traceln

func Traceln(req *http.Request, message ...interface{})

Traceln logs a message at Trace level

func Warnf

func Warnf(req *http.Request, format string, args ...interface{})

Warnf logs a message at Warn level

func Warnln

func Warnln(req *http.Request, message ...interface{})

Warnln logs a message at Warn level

Types

type Level

type Level int

Level is a log level

func LevelFromString

func LevelFromString(level string) (Level, error)

LevelFromString returns a log level from a string

Jump to

Keyboard shortcuts

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