flogger

package module
v0.0.0-...-f7a4368 Latest Latest
Warning

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

Go to latest
Published: May 27, 2016 License: BSD-2-Clause Imports: 4 Imported by: 3

README

Flogger

###SUMMARY

Flogger provides a simple wrapper around go's base logging module to provide logging levels. Flogger provides the following features.

  • Logging levels capable of overloading output in desired language.
  • Allow redirection of stdout and stderr to capture panics and other messages.
  • Other packages can import and use flogger without having to define a specific logger.
  • If a logfile is not configured, output will log to stdout.
  • Is go routine safe.

###Example

package main

import (
    log "github.com/zdannar/flogger"
)

const (
    LOGFILE = "/tmp/example.log"
)


func main() {
    if err := log.OpenFile(LOGFILE, log.FLOG_APPEND, 0644); err != nil {
        log.Fatalf("Unable to open log file : %s", err)
    }
    log.SetLevel(log.INFO)

    log.RedirectStreams()

    log.Debugf("My name is %s", "mud")
    log.Infof("My name is %s", "Chuck Norris")
    log.Panic(" OH NO!... Don't panic!")
}

The output of /tmp/example.log

2013/10/13 17:33:38 logtest.go:21: : INFO : My name is Chuck Norris
2013/10/13 17:33:38 logtest.go:22: : PANIC :  OH NO!... Don't panic!
panic: : PANIC :  OH NO!... Don't panic!

goroutine 1 [running]:
github.com/ryanchapman/go-any-proxy/flogger.(*Flogger).flog(0xc20004b100, 0x5, 0x7f418ef8af78, 0x1, 0x1, ...)
        /home/zdannar/go_include/src/github.com/ryanchapman/go-any-proxy/flogger/flogger.go:71 +0x1e1
github.com/ryanchapman/go-any-proxy/flogger.(*Flogger).Panic(0xc20004b100, 0x7f418ef8af78, 0x1, 0x1)
        /home/zdannar/go_include/src/github.com/ryanchapman/go-any-proxy/flogger/flogger.go:136 +0x4c
github.com/ryanchapman/go-any-proxy/flogger.Panic(0x7f418ef8af78, 0x1, 0x1)
        /home/zdannar/go_include/src/github.com/ryanchapman/go-any-proxy/flogger/base.go:94 +0x46
main.main()
        /home/zdannar/gitroot/qa-site-tank/go_include/logtest.go:22 +0x30d

goroutine 2 [runnable]:

###INSTALL

go get github.com/zdannar/flogger

Documentation

Overview

Flogger provides a simple wrapper around go's base logging library to provide logging levels. Further documentation can be found at https://github.com/zdannar/flogger

Index

Constants

View Source
const (
	DEBUG int = iota
	INFO
	WARNING
	ERROR
	FATAL
	PANIC
)
View Source
const (
	STDOUT = iota + 1
	STDERR
)

Variables

View Source
var (
	FLOG_APPEND int = os.O_WRONLY | os.O_APPEND | os.O_CREATE
	FLOG_FORMAT int = log.LstdFlags | log.Lshortfile

	FLOG_LEVELS = map[int]string{
		DEBUG:   "DEBUG",
		INFO:    "INFO",
		WARNING: "WARNING",
		ERROR:   "ERROR",
		FATAL:   "FATAL",
		PANIC:   "PANIC",
	}
)

Functions

func Close

func Close() error

Closes default logger's file descriptor.

func Debug

func Debug(args ...interface{})

Calls f.Debug() on base logging object.

func Debugf

func Debugf(msg string, args ...interface{})

Calls f.Debugf() on base logging object.

func Error

func Error(args ...interface{})

Calls f.Error() on base logging object.

func Errorf

func Errorf(msg string, args ...interface{})

Calls f.Errorf() on base logging object.

func Fatal

func Fatal(args ...interface{})

Calls f.Fatal() on base logging object.

func Fatalf

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

Calls f.Fatalf() on base logging object.

func Info

func Info(args ...interface{})

Calls f.Info() on base logging object.

func Infof

func Infof(msg string, args ...interface{})

Calls f.Infof() on base logging object.

func OpenFile

func OpenFile(logPath string, openMode int, perms os.FileMode) error

Opens default logger's file for writing.

func Panic

func Panic(args ...interface{})

Calls f.Panic() on base logging object.

func Panicf

func Panicf(msg string, args ...interface{})

Calls f.Panicf() on base logging object.

func RedirectStreams

func RedirectStreams() error

Calls f.RedirectStreams() on base logging object.

func SetLevel

func SetLevel(level int)

Sets the default logger's logging level.

func SetLevelMap

func SetLevelMap(lmap map[int]string)

Sets the default logger's level map.

func Warning

func Warning(args ...interface{})

Calls f.Warning() on base logging object.

func Warningf

func Warningf(msg string, args ...interface{})

Calls f.Warningf() on base logging object.

Types

type Flogger

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

Flogger structure.

func New

func New(logLevel, logFormat int, levelMap map[int]string) *Flogger

Returns a flogger.Flogger structure for logging.

func (*Flogger) Close

func (f *Flogger) Close() error

Flushes and closes file descriptor that flogger is logging to. Should always be called at the end of execution.

func (*Flogger) Debug

func (f *Flogger) Debug(args ...interface{})

Logs to the debugging logging channel

func (*Flogger) Debugf

func (f *Flogger) Debugf(msg string, args ...interface{})

Debug function with string formatting

func (*Flogger) Error

func (f *Flogger) Error(args ...interface{})

Logs to the error logging channel

func (*Flogger) Errorf

func (f *Flogger) Errorf(msg string, args ...interface{})

Error function with string formatting

func (*Flogger) Fatal

func (f *Flogger) Fatal(args ...interface{})

Logs your message, then calls os.Exit(1).

func (*Flogger) Fatalf

func (f *Flogger) Fatalf(msg string, args ...interface{})

Fatal function with string formatting

func (*Flogger) Info

func (f *Flogger) Info(args ...interface{})

Logs to the info logging channel

func (*Flogger) Infof

func (f *Flogger) Infof(msg string, args ...interface{})

Info function with string formatting

func (*Flogger) OpenFile

func (f *Flogger) OpenFile(logPath string, openMode int, perms os.FileMode) error

Opens a file for flogger to log to.

func (*Flogger) Panic

func (f *Flogger) Panic(args ...interface{})

Panics with your message.

func (*Flogger) Panicf

func (f *Flogger) Panicf(msg string, args ...interface{})

Panic function with string formatting

func (*Flogger) RedirectStream

func (f *Flogger) RedirectStream(fd int) error

Redirects file descriptor to log file. Example: flogger.RedirectStream(flogger.STDERR)

func (*Flogger) RedirectStreams

func (f *Flogger) RedirectStreams() error

Redirects stdout and stderr to log file. Very handy to catch the output of panics in your log file.

func (*Flogger) SetLevel

func (f *Flogger) SetLevel(level int)

Sets the logger level. Usually called with flogger.INFO, flogger.DEBUG, etc...

func (*Flogger) SetLevelMap

func (f *Flogger) SetLevelMap(lmap map[int]string)

Sets logging level map. Provides the abilty to change level messages. Default logger uses flogger.FLOG_LEVELS

func (*Flogger) Warning

func (f *Flogger) Warning(args ...interface{})

Logs to the warning logging channel

func (*Flogger) Warningf

func (f *Flogger) Warningf(msg string, args ...interface{})

Warning function with string formatting

Jump to

Keyboard shortcuts

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