log

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

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

Go to latest
Published: Oct 18, 2016 License: MIT Imports: 6 Imported by: 0

README

GoDoc

Eye Log

This is a simple logging package that allows the following:

  • Configuration with environment variables
  • 2 logging levels, with prefixed output and ability to turn off all logging
  • Configurable output, at least what the standard logging library allows

Usage

Out of the box you can have 2 levels of logging to stdout.

package main

import "github.com/eyesore/log"

func main() {
    log.Debug("Hello", "World")
    log.Debugf("Hello %s", "World")
    log.Info("Hello", "Again!")

    // runtime configuration
    log.SetInfoOut("/tmp/debug.log")
    log.Infof("Hello %s", "Again!") // writes to /tmp/debug.log
    log.SetDebugFlags("date,microseconds,shortfile")
    log.Debug("More information in output.")
    // [DEBUG]  2016/06/10 22:55:06.500921 main.go:19
}

You can also configure all of these options using environment variables.

Environment Variables

The following environment variables can be set to change the logging behavior:

  • EYELOG_DEBUG_OUT
  • EYELOG_INFO_OUT

Both of these default to os.Stdout. Setting the variables to a filename will cause the logs for that level to be written to that file. If it does not exist, the file will be created, but if the directory does not exist, that output will be set to the default.

  • EYELOG_LEVEL

Valid values are 0 (no logging), 1 (only INFO), and 2 (all levels)

Flags

Flags control the configuration of the log output.

  • EYELOG_FLAGS_DEFAULT

Default flags that will be used if a configuration is not specified for a logger.

  • EYELOG_FLAGS_DEBUG
  • EYELOG_FLAGS_INFO

Configuration flags that will override the default flags for that log level.

The following flags are allowed:

  • date - YYYY/MM/DD timestamp for each log entry
  • time - HH:MM:SS timestamp for each log entry
  • microseconds - HH:MM:SS.mmmmmm timestamp for each log entry. Replaces "time"
  • shortfile - Filename and line number from which the log entry was generated. Always overrides longfile if both are present.
  • longfile - Full path to file and line number from which the log entry was generated.
  • UTC - Use UTC for timestamps instead of system time.

Multiple flags can be set as follows:

EYELOG_FLAGS_DEFAULT=date,time,shortfile,UTC

EYELOG_FLAGS_DEBUG=microtime

If no flags are configured, the default is date,time There is currently no way to turn off all flags, but you can have just one if you like.

Runtime Configuration

Environment variables are read at startup, but some methods are exported for changing logger configuration at runtime.

See the documentation for details.

Documentation

Overview

Package log is a simple logging package that exposes configuration through environment variables.

Index

Constants

View Source
const (
	// OutStdout can be passed to runtime output configuration methods to reset them
	// to os.Stdout
	OutStdout = "STDOUT"

	LevelDebug int8 = 2
	LevelInfo  int8 = 1
	LevelNone  int8 = 0
)

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug logs debug output. Args are in the style of fmt.Println

func Debugf

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

Debugf logs debug output. Args are in the style of fmt.Printf

func Fatal

func Fatal(v ...interface{})

Fatal logs to stderr and stops program execution (os.Exit) Args are in the style of fmt.Print

func Fatalf

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

Fatalf logs to sterr and stops program execution (os.Exit) Args are in the style of fmt.Printf

func Info

func Info(v ...interface{})

Info logs info output. Args are in the style of fmt.Println

func Infof

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

Infof logs info output. Args are in the style of fmt.Printf

func SetDebugFlags

func SetDebugFlags(flags string)

SetDebugFlags changes the content of the debug output with a comma-separated list of flags. Valid flags are date,time,microseconds,shortfile,longfile,UTC

func SetDebugOut

func SetDebugOut(location string)

SetDebugOut sets the debug output to a file at location You can pass log.OutStdout to log debug level to os.Stdout

func SetDebugOutDirect

func SetDebugOutDirect(w io.Writer)

SetDebugOutDirect sets the debug output directly to the given Writer w.

func SetDefaultFlags

func SetDefaultFlags(flags string)

SetDefaultFlags sets flags that will be used for logging adapters with no flags configured. Valid flags are date,time,microseconds,shortfile,longfile,UTC

func SetInfoFlags

func SetInfoFlags(flags string)

SetInfoFlags changes the content of the info output with a comma-separated list of flags. Valid flags are date,time,microseconds,shortfile,longfile,UTC

func SetInfoOut

func SetInfoOut(f string)

SetInfoOut sets the info output to a file at location You can pass log.OutStdout to log info level to os.Stdout

func SetInfoOutDirect

func SetInfoOutDirect(w io.Writer)

SetInfoOutDirect sets the info output directly to the given Writer w.

func SetLevel

func SetLevel(l int8)

SetLevel updates the log level at runtime. Valid values are log.LevelDebug, log.LevelInfo, log.LevelNone

Types

This section is empty.

Jump to

Keyboard shortcuts

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