flog

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

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

Go to latest
Published: Aug 22, 2016 License: BSD-3-Clause Imports: 7 Imported by: 1

README

This is still here for reference, but I recommend you use https://github.com/uber-go/zap as those folks have done a really great job at quick (to use and to run) and flexible logging.


Flog

Development Repository

Experimental: No stable version of this package yet exists; it is still in early development.

Package flog provides a logging facility with the usual syslog-style levels of Critical, Error, Warning, Info, and Debug. It just uses os.Stderr and os.Stdout by default, and it's mostly here to provide a quick, easy, yet replaceable way to do logging.

API Documentation

This is the latest development area for the package.
Eventually a stable version of the package will be established but, for now, all things about this package are subject to change.

Copyright See AUTHORS. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.

Documentation

Overview

Package flog provides a logging facility with the usual syslog-style levels of Critical, Error, Warning, Info, and Debug. It just uses os.Stderr and os.Stdout by default, and it's mostly here to provide a quick, easy, yet replaceable way to do logging.

Index

Constants

This section is empty.

Variables

View Source
var Default = New(nil)

Default is an instance of Flog for ease of use. Though I'd recommend writing your code to accept a Flog or Logger so others can alter it later; this Default can be changed to indirectly have a similar effect.

Functions

func CriticalPrintf

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

CriticalPrintf is a convenience function equivalent to Default.CriticalPrintf.

func CriticalPrintln

func CriticalPrintln(args ...interface{})

CriticalPrintln is a convenience function equivalent to Default.CriticalPrintln.

func DebugPrintf

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

DebugPrintf is a convenience function equivalent to Default.DebugPrintf.

func DebugPrintln

func DebugPrintln(args ...interface{})

DebugPrintln is a convenience function equivalent to Default.DebugPrintln.

func ErrorPrintf

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

ErrorPrintf is a convenience function equivalent to Default.ErrorPrintf.

func ErrorPrintln

func ErrorPrintln(args ...interface{})

ErrorPrintln is a convenience function equivalent to Default.ErrorPrintln.

func InfoPrintf

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

InfoPrintf is a convenience function equivalent to Default.InfoPrintf.

func InfoPrintln

func InfoPrintln(args ...interface{})

InfoPrintln is a convenience function equivalent to Default.InfoPrintln.

func WarningPrintf

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

WarningPrintf is a convenience function equivalent to Default.WarningPrintf.

func WarningPrintln

func WarningPrintln(args ...interface{})

WarningPrintln is a convenience function equivalent to Default.WarningPrintln.

Types

type Config

type Config struct {
	// Name will be used in the prefix of each log line.
	Name string
	// CriticalWriter will accept Critical level log output. If set to nil, the
	// default os.Stderr will be used. To discard all Critical level output,
	// set to an instance of brimio.NullIO.
	CriticalWriter io.Writer
	// ErrorWriter will accept Error level log output. If set to nil, the
	// default os.Stderr will be used. To discard all Error level output, set
	// to an instance of brimio.NullIO.
	ErrorWriter io.Writer
	// WarningWriter will accept Warning level log output. If set to nil, the
	// default os.Stderr will be used. To discard all Warning level output, set
	// to an instance of brimio.NullIO.
	WarningWriter io.Writer
	// InfoWriter will accept Info level log output. If set to nil, the default
	// os.Stdout will be used. To discard all Info level output, set to
	// an instance of brimio.NullIO.
	InfoWriter io.Writer
	// DebugWriter will accept Debug level log output. If set to nil, the
	// default is to discard all Debug level output.
	DebugWriter io.Writer
}

Config is used when creating a new Flog instance.

type Flog

type Flog interface {
	// CriticalPrintf logs the result of fmt.Sprintf(format, args).
	CriticalPrintf(format string, args ...interface{})
	// CriticalPrintln logs the result of fmt.Sprintln(args).
	CriticalPrintln(args ...interface{})
	// ErrorPrintf logs the result of fmt.Sprintf(format, args).
	ErrorPrintf(format string, args ...interface{})
	// ErrorPrintln logs the result of fmt.Sprintln(args).
	ErrorPrintln(args ...interface{})
	// WarningPrintf logs the result of fmt.Sprintf(format, args).
	WarningPrintf(format string, args ...interface{})
	// WarningPrintln logs the result of fmt.Sprintln(args).
	WarningPrintln(args ...interface{})
	// InfoPrintf logs the result of fmt.Sprintf(format, args).
	InfoPrintf(format string, args ...interface{})
	// InfoPrintln logs the result of fmt.Sprintln(args).
	InfoPrintln(args ...interface{})
	// DebugPrintf logs the result of fmt.Sprintf(format, args).
	DebugPrintf(format string, args ...interface{})
	// DebugPrintln logs the result of fmt.Sprintln(args).
	DebugPrintln(args ...interface{})
	// Sub creates a new Flog instance based on this one, possibly with
	// overrides from the given Config. If Config.Name is set, it will be
	// appended to the original Flog instance's name.
	Sub(c *Config) Flog
}

Flog provides a logging facility with the usual syslog-style levels of Critical, Error, Warning, Info, and Debug.

func New

func New(c *Config) Flog

New returns a new Flog instance based on the Config given.

func Sub

func Sub(c *Config) Flog

Sub is a convenience function equivalent to Default.Sub.

type Logger

type Logger interface {
	// Fatal is equivalent to Print() followed by a call to os.Exit(1).
	Fatal(args ...interface{})
	// Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
	Fatalf(format string, args ...interface{})
	// Fatalln is equivalent to Println() followed by a call to os.Exit(1).
	Fatalln(args ...interface{})
	// Print calls Output to print to the standard logger. Arguments are
	// handled in the manner of fmt.Print.
	Print(args ...interface{})
	// Printf calls Output to print to the standard logger. Arguments are
	// handled in the manner of fmt.Printf.
	Printf(format string, args ...interface{})
	// Println calls Output to print to the standard logger. Arguments are
	// handled in the manner of fmt.Println.
	Println(args ...interface{})
}

Logger is an interface to match the most common calls to the standard library's log.Logger.

func CriticalLogger

func CriticalLogger(f Flog) Logger

CriticalLogger returns a Logger instance that will send its output to the Critical level of the Flog given.

func DebugLogger

func DebugLogger(f Flog) Logger

DebugLogger returns a Logger instance that will send its output to the Debug level of the Flog given.

func ErrorLogger

func ErrorLogger(f Flog) Logger

ErrorLogger returns a Logger instance that will send its output to the Error level of the Flog given.

func InfoLogger

func InfoLogger(f Flog) Logger

InfoLogger returns a Logger instance that will send its output to the Info level of the Flog given.

func WarningLogger

func WarningLogger(f Flog) Logger

WarningLogger returns a Logger instance that will send its output to the Warning level of the Flog given.

Jump to

Keyboard shortcuts

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