Help us shape the future of Go! Take the 2026 Go Developer Survey

logging

package module
v0.0.0-...-8f1e2ce Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2014 License: Apache-2.0 Imports: 9 Imported by: 1

README

go-logging

Package logging provides a simple leveled logging API

Installation

$ go get github.com/davidnarayan/go-logging

Quick Start

package main

import (
    "os"
    "github.com/davidnarayan/go-logging"
)

func main() {
    // Basic usage
    logging.Debug("This is a debug message")
    logging.Info("This is an info message")
    logging.Warn("This is a warning message")
    logging.Error("This is an error message")

    // Note: Fatal() calls os.Exit(1)
    // logging.Fatal("This is a fatal message")

    // ... with format strings
    foo := "bar"
    logging.Info("This is an info message with a parameter foo=%s", foo)

    // Change the output destination
    logging.Info("This message goes to STDERR")
    logging.SetWriter(os.Stdout)
    logging.Info("This message goes to STDOUT")

    // Change the logging level
    logging.SetLevel(logging.ERROR)
    logging.Info("This message won't be displayed")
    logging.Error("This message will be displayed")
}

Documentation

Index

Constants

View Source
const (
	TRACE = iota
	DEBUG
	INFO
	WARN
	ERROR
	FATAL
	STATS
)

Log levels

Variables

This section is empty.

Functions

func Debug

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

func Error

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

func Fatal

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

func Info

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

func SetLevel

func SetLevel(level Level)

func SetWriter

func SetWriter(w io.Writer)

func Stats

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

func Trace

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

func Warn

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

Types

type Level

type Level int

Log levels are used to control the level of verbosity in the logs

func (Level) String

func (level Level) String() string

type Logger

type Logger struct {
	Name   string
	Level  Level
	Writer io.Writer
	// contains filtered or unexported fields
}

A Logger writes out log messages

func (*Logger) Log

func (l *Logger) Log(level Level, format string, v ...interface{})

Log a message

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

Set the minimum log level

func (*Logger) SetName

func (l *Logger) SetName(name string)

Set the logger name

func (*Logger) SetWriter

func (l *Logger) SetWriter(w io.Writer)

Set the output destination

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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