loglevel

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2017 License: Apache-2.0 Imports: 4 Imported by: 2

README

loglevel-go

Standard out formatter that supports log levels and coloured output.

Get started

go get github.com/amimof/loglevel-go

package main

import "github.com/amimof/loglevel-go"

func main() {
    
}

Example

package main

import "github.com/amimof/loglevel-go"

func main() {
    // Create an instance of loglevel
    log := loglevel.SetupNew("MyLogger")
    
    // Set loglevel. 3=Debug, 2=Info, 1=Warn, 0=Error. Defaults to Info.
    log.Level.SetLevel(3)
    
    // Log away
    log.Debug("Debug message")
    log.Info("Info message")
    log.Warn("Warn message")
    log.Errorf("Error message")
    
    // Also supports formatting
    fname := "Luke"
    lname := "Skywalker"
    log.Infof("The Jedi %s, %s", fname, lname)
}

Documentation

Index

Constants

View Source
const (
	CLR_0 = "\x1b[30;1m"
	CLR_R = "\x1b[31;1m"
	CLR_G = "\x1b[32;1m"
	CLR_Y = "\x1b[33;1m"
	CLR_B = "\x1b[34;1m"
	CLR_M = "\x1b[35;1m"
	CLR_C = "\x1b[36;1m"
	CLR_W = "\x1b[37;1m"
	CLR_N = "\x1b[0m"
	DEBUG = 3
	INFO  = 2
	WARN  = 1
	ERROR = 0
)

Define colors

Variables

This section is empty.

Functions

func SetOutput

func SetOutput(out io.Writer)

Set the standard logger output

Types

type Level

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

func (*Level) SetLevel

func (l *Level) SetLevel(level int) *Level

type Logger

type Logger struct {
	Level *Level
	// contains filtered or unexported fields
}

func SetupNew

func SetupNew(name string) *Logger

Setup and return logger

func (*Logger) Debug

func (l *Logger) Debug(message ...interface{})

Prints a debug message on a new line

func (*Logger) Debugf

func (l *Logger) Debugf(format string, message ...interface{})

Prints according to fmt.Sprintf format specifier and returns the resulting string

func (*Logger) Error

func (l *Logger) Error(message ...interface{})

Prints an error message on a new line

func (*Logger) Errorf

func (l *Logger) Errorf(format string, message ...interface{})

Prints according to fmt.Sprintf format specifier and returns the resulting string

func (*Logger) GetLevel

func (l *Logger) GetLevel() *Level

Return the level

func (*Logger) Info

func (l *Logger) Info(message ...interface{})

Prints n info message on a new line

func (*Logger) Infof

func (l *Logger) Infof(format string, message ...interface{})

Prints according to fmt.Sprintf format specifier and returns the resulting string

func (*Logger) New

func (l *Logger) New(name string, level *Level) *Logger

func (*Logger) Warn

func (l *Logger) Warn(message ...interface{})

Prints a warning message on a new line

func (*Logger) Warnf

func (l *Logger) Warnf(format string, message ...interface{})

Prints according to fmt.Sprintf format specifier and returns the resulting string

type StandardLogger

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

func NewStdLogger

func NewStdLogger(out io.Writer) *StandardLogger

func (*StandardLogger) Output

func (l *StandardLogger) Output(color, str string) error

Writes the specified string to std and colors it accordingly

Jump to

Keyboard shortcuts

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