gologit

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

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

Go to latest
Published: Apr 18, 2016 License: MIT Imports: 5 Imported by: 2

README

gologit

A simple wrapper for Go "log" that provides toggle-able debug support.

NOTE: gologit is currently deprecated. Check out mlog instead.

Installation

$ go get github.com/cactus/gologit

Usage

Simplest:

import (
    "flag"
    "github.com/cactus/gologit"
)

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    // set debug true/false
    gologit.Logger.Set(*debug)
    // this prints only if debug is true
    gologit.Logger.Debugln("Debug Logging enabled!")
}

Simple:

import (
    "flag"
    "github.com/cactus/gologit"
)

// alias exported gologit Logger to a short name for convenience
var logger = gologit.Logger

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    logger.Set(*debug)
    logger.Debugln("Logging enabled")
}

When you don't want to share:

import (
    "flag"
    "github.com/cactus/gologit"
)

// make a new one (unique to this module)
var logger = gologit.New(false)

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    logger.Set(*debug)
    logger.Debugln("Logging enabled")
}

Pass it like a logging potato:

import (
    "flag"
    "github.com/cactus/gologit"
)

// make a new one (unique to this module)
var logger = gologit.New(false)

func main() {
    debug := flag.Bool("debug", false, "Enable Debug Logging")
    flag.Parse()

    logger := gologit.New(*debug)
    logger.Debugln("Logging enabled")
    SomeOtherFunc(logger)
}

Documentation

More documentation available at go.pkgdoc.org

License

Released under the MIT license. See LICENSE file for details.

Documentation

Overview

Package gologit implements a very simple wrapper around the Go "log" package, providing support for a toggle-able debug flag and a couple of functions that log or not based on that flag.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Logger = New(false)

Functions

func Debug

func Debug(v ...interface{})

Logs to the default Logger. See Logger.Debug

func Debugf

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

Logs to the default Logger. See Logger.Debugf

func Debugln

func Debugln(v ...interface{})

Logs to the default Logger. See Logger.Debugln

func Fatal

func Fatal(v ...interface{})

Logs to the default Logger. See Logger.Fatal

func Fatalf

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

Logs to the default Logger. See Logger.Fatalf

func Fatalln

func Fatalln(v ...interface{})

Logs to the default Logger. See Logger.Fatalln

func Panic

func Panic(v ...interface{})

Logs to the default Logger. See Logger.Panic

func Panicf

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

Logs to the default Logger. See Logger.Panicf

func Panicln

func Panicln(v ...interface{})

Logs to the default Logger. See Logger.Panicln

func Print

func Print(v ...interface{})

Logs to the default Logger. See Logger.Print

func Printf

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

Logs to the default Logger. See Logger.Printf

func Println

func Println(v ...interface{})

Logs to the default Logger. See Logger.Println

func Set

func Set(debug bool)

Sets the state of the default Logger. See Logger.Set

func State

func State() bool

Gets the state of the default Logger. See Logger.State

func Toggle

func Toggle()

Toggles the debug state of the default Logger. See Logger.Toggle

func ToggleOnSignal

func ToggleOnSignal(sig os.Signal)

Types

type DebugLogger

type DebugLogger struct {
	*log.Logger
	// contains filtered or unexported fields
}

A DebugLogger represents a logging object, that embeds log.Logger, and provides support for a toggle-able debug flag.

func New

func New(debug bool) *DebugLogger

New creates a new DebugLogger. The debug argument specifies whether debug should be set or not.

Example
package main

import (
	"github.com/cactus/gologit"
)

func main() {
	logger := gologit.New(true)
	logger.Debug("It works!")
}

func (*DebugLogger) Debug

func (l *DebugLogger) Debug(v ...interface{})

Debug calls log.Print if debug is true. If debug is false, does nothing.

func (*DebugLogger) Debugf

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

Debugf calls log.Printf if debug is true. If debug is false, does nothing.

func (*DebugLogger) Debugln

func (l *DebugLogger) Debugln(v ...interface{})

Debugln calls log.Println if debug is true. If debug is false, does nothing.

func (*DebugLogger) Set

func (l *DebugLogger) Set(debug bool)

Set the debug state directly.

func (*DebugLogger) State

func (l *DebugLogger) State() bool

func (*DebugLogger) Toggle

func (l *DebugLogger) Toggle()

Toggles the debug state. If debug is true, sets it to false. If debug is false, sets it to true.

func (*DebugLogger) ToggleOnSignal

func (l *DebugLogger) ToggleOnSignal(sig os.Signal)

Directories

Path Synopsis
Package slog implements a very simple levelled logger
Package slog implements a very simple levelled logger

Jump to

Keyboard shortcuts

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