loglevel

package module
v0.0.0-...-3bb4128 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2013 License: MIT Imports: 5 Imported by: 8

README

loglevel Build Status

This project aims to be the simplest and best-tested levelled logging wrapper around go's standard library log module. It retains as much of the same API as possible.

Installation

go get -u github.com/llimllib/loglevel

Documentation

You can find the documentation over at GoDoc

Contributors

(alphabetical order)

History

Originally derived from oneslang's log library but significantly modified by Bill Mill.

Example

package main

import (
	"bytes"
	"fmt"
	log "github.com/llimllib/loglevel"
)

func main() {
	// Set output level to info
	log.SetPriorityString("info")

    log.Info("Which means this will get printed")
	log.Warn("As will this")
    log.Debug("But not this")

	log.Info("The possible levels, in order from low to high:")
	log.Info("trace, debug, info, warn, error, fatal")

	// Just like the log module, you can set a prefix
	log.SetPrefix("OMG A PREFIX ")
	log.Info("Man that prefix is probably annoying")
	log.SetPrefix("")

	// You can also change what info is output in the prefix of each log msg
	log.SetFlags(log.Lshortfile | log.Lpriority)
	log.Info("Possible flags: Ldate, Ltime, Lmicroseconds, Llongfile")
	log.Info("                Lshortfile, Lpriority, LstdFlags = Ldate | Ltime")

	// Each log level has a format version and an ln version
	str := "this"
	log.Infof("Like %s", str)
	log.Errorln("Or this")

	// You can also make a log object; create a logger that outputs to buf, has
	// no prefix, outputs the standard line info, and prints logs at level info
	// and above
	buf := new(bytes.Buffer)
	l := log.New(buf, "", log.LstdFlags, log.Pinfo)
	l.Warn("This is a warning")
	fmt.Print(buf.String())

	// You can cause your program to exit with Fatal, Fatalf, or Fatalln
	log.Fatal("the program will terminate here")
	log.Info("so this line will not get printed")
	
	// You can also use the panic series of functions to print a message
	// followed by a traceback, and exit your program
	log.Panic("If we got here, this would exit and print a traceback")
}

Documentation

Overview

Package loglevel aims to be the simplest and best-tested levelled logging wrapper around go's standard library log module. It retains as much of the same API as possible.

Index

Constants

View Source
const (
	Poff = iota
	Pfatal
	Perror
	Pwarn
	Pinfo
	Pdebug
	Ptrace
	Pall
)

Priority used for identifying the severity of an event.

View Source
const (
	Ldate         = 1 << iota     // the date: 2012/01/23
	Ltime                         // the time: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	Lpriority                     // the priority: Debug
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
)

Flags used for identifying the format of an event. They are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). A colon appears after these items:

2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug prints to the standard logger with the Debug level.

func Debugf

func Debugf(format string, v ...interface{})

Debugf prints to the standard logger with the Debug level.

func Debugln

func Debugln(v ...interface{})

Debugln prints to the standard logger with the Debug level.

func Error

func Error(v ...interface{})

Error prints to the standard logger with the Error level.

func Errorf

func Errorf(format string, v ...interface{})

Errorf prints to the standard logger with the Error level.

func Errorln

func Errorln(v ...interface{})

Errorln prints to the standard logger with the Error level.

func Fatal

func Fatal(v ...interface{})

Fatal prints the message it's given and quits the program

func Fatalf

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

Fatalf prints the message it's given and quits the program

func Fatalln

func Fatalln(v ...interface{})

Fatalln prints the message it's given and quits the program

func Flags

func Flags() int

Flags returns the output layouts for the standard logger.

func Info

func Info(v ...interface{})

Info prints to the standard logger with the Info level.

func Infof

func Infof(format string, v ...interface{})

Infof prints to the standard logger with the Info level.

func Infoln

func Infoln(v ...interface{})

Infoln prints to the standard logger with the Info level.

func Panic

func Panic(v ...interface{})

Panic prints the message it's given and panic()s the program

func Panicf

func Panicf(format string, v ...interface{})

Panicf prints the message it's given and panic()s the program

func Panicln

func Panicln(v ...interface{})

Panicln prints the message it's given and panic()s the program

func Priority

func Priority() int

Priority returns the output priority for the standard logger.

func SetFlags

func SetFlags(flags int)

SetFlags sets the output layouts for the standard logger.

func SetOutput

func SetOutput(out io.Writer)

SetOutput sets the output destination for the standard logger

func SetPrefix

func SetPrefix(prefix string)

SetPrefix sets the logger prefix

func SetPriority

func SetPriority(priority int)

SetPriority sets the output priority for the standard logger.

func SetPriorityString

func SetPriorityString(s string) error

SetPriorityString sets the output priority by the name of a debug level

func Trace

func Trace(v ...interface{})

Trace prints to the standard logger with the Trace level.

func Tracef

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

Tracef prints to the standard logger with the Trace level.

func Traceln

func Traceln(v ...interface{})

Traceln prints to the standard logger with the Trace level.

func Warn

func Warn(v ...interface{})

Warn prints to the standard logger with the Warn level.

func Warnf

func Warnf(format string, v ...interface{})

Warnf prints to the standard logger with the Warn level.

func Warnln

func Warnln(v ...interface{})

Warnln prints to the standard logger with the Warn level.

Types

type Logger

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

Logger defines our wrapper around the system logger

func New

func New(out io.Writer, prefix string, flag int, priority int) *Logger

New creates a new Logger.

func (*Logger) Debug

func (me *Logger) Debug(v ...interface{})

Debug prints to the standard logger with the Debug level.

func (*Logger) Debugf

func (me *Logger) Debugf(format string, v ...interface{})

Debugf prints to the standard logger with the Debug level.

func (*Logger) Debugln

func (me *Logger) Debugln(v ...interface{})

Debugln prints to the standard logger with the Debug level.

func (*Logger) Error

func (me *Logger) Error(v ...interface{})

Error prints to the standard logger with the Error level.

func (*Logger) Errorf

func (me *Logger) Errorf(format string, v ...interface{})

Errorf prints to the standard logger with the Error level.

func (*Logger) Errorln

func (me *Logger) Errorln(v ...interface{})

Errorln prints to the standard logger with the Error level.

func (*Logger) Fatal

func (me *Logger) Fatal(v ...interface{})

Fatal prints the message it's given and quits the program

func (*Logger) Fatalf

func (me *Logger) Fatalf(format string, v ...interface{})

Fatalf prints the message it's given and quits the program

func (*Logger) Fatalln

func (me *Logger) Fatalln(v ...interface{})

Fatalln prints the message it's given and quits the program

func (*Logger) Flags

func (me *Logger) Flags() int

Flags returns the output layouts for the logger.

func (*Logger) Info

func (me *Logger) Info(v ...interface{})

Info prints to the standard logger with the Info level.

func (*Logger) Infof

func (me *Logger) Infof(format string, v ...interface{})

Infof prints to the standard logger with the Info level.

func (*Logger) Infoln

func (me *Logger) Infoln(v ...interface{})

Infoln prints to the standard logger with the Info level.

func (*Logger) Panic

func (me *Logger) Panic(v ...interface{})

Panic prints the message it's given and panic()s the program

func (*Logger) Panicf

func (me *Logger) Panicf(format string, v ...interface{})

Panicf prints the message it's given and panic()s the program

func (*Logger) Panicln

func (me *Logger) Panicln(v ...interface{})

Panicln prints the message it's given and panic()s the program

func (*Logger) Prefix

func (me *Logger) Prefix() string

Prefix returns the current logger prefix

func (*Logger) Priority

func (me *Logger) Priority() int

Priority returns the output priority for the logger.

func (*Logger) SetFlags

func (me *Logger) SetFlags(layouts int)

SetFlags sets the output layouts for the logger.

func (*Logger) SetPrefix

func (me *Logger) SetPrefix(prefix string)

SetPrefix sets the output prefix for the logger.

func (*Logger) SetPriority

func (me *Logger) SetPriority(priority int)

SetPriority sets the output priority for the logger.

func (*Logger) SetPriorityString

func (me *Logger) SetPriorityString(s string) error

SetPriorityString sets the output priority by the name of a debug level

func (*Logger) Trace

func (me *Logger) Trace(v ...interface{})

Trace prints to the standard logger with the Trace level.

func (*Logger) Tracef

func (me *Logger) Tracef(format string, v ...interface{})

Tracef prints to the standard logger with the Trace level.

func (*Logger) Traceln

func (me *Logger) Traceln(v ...interface{})

Traceln prints to the standard logger with the Trace level.

func (*Logger) Warn

func (me *Logger) Warn(v ...interface{})

Warn prints to the standard logger with the Warn level.

func (*Logger) Warnf

func (me *Logger) Warnf(format string, v ...interface{})

Warnf prints to the standard logger with the Warn level.

func (*Logger) Warnln

func (me *Logger) Warnln(v ...interface{})

Warnln prints to the standard logger with the Warn level.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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