klog

package
Version: v0.0.0-...-a69649c Latest Latest
Warning

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

Go to latest
Published: May 26, 2014 License: BSD-3-Clause, GPL-2.0 Imports: 8 Imported by: 0

README

klog

Build Status

library for golang

First thanks to the 3 people who stars of the project beelog which encouraged me to rewrite beelog, and klog comes out.

klog learn from a lot other log system for golang, like beego, seelog, glog, qiniu-log.

Introdution

From my experience of some project. I think there are only 5 level needed. Debug Info Warning Error Fatal

Default level is Info. Use SetLevel(level) to change.

Default output style is

prefix 2006/01/02 03:04:05 [INFO] hello world

Use SetFlags(klog.Fdevflag) will change output to

prefix 2006/01/02 03:04:05 [INFO] hello.go:7 hello world

Color output is default enabled in console, and auto closed when redirected to a file.

DEBUG  "Cyan",
INFO   "Green",
WARN   "Magenta",
ERROR  "Yellow",
FATAL  "Red",

How to use

below this is a simple example

More usage please reference http://gowalker.org/github.com/shxsun/klog

go get github.com/shxsun/klog

package main
import "github.com/shxsun/klog"

func main(){
	// Example 1
	// use klog.StdLog, klog.DevLog for logging
	klog.StdLog.Warnf("Hello world")
	// output: 2013/12/01 12:00:00 [Warn] Hello world
	// StdLog default level is Warning
	
	klog.DevLog.Debugf("Nice")
	// output: 2013/12/01 12:00:00 main.go:12 [DEBUG] Hello world
	
	// Example 2
	k2 := klog.NewLogger(nil) // Write to stdout
	//k := klog.NewLogger(nil, "option-prefix") // with prefix
	
	// Example 3
	k3, err := klog.NewFileLogger("app.log")
	if err != nil { ...	}

	k = klog.DevLog
	k.Infof("Hi %s.", "Susan")
	k.Warn("Oh my god, you are alive!")
	k.Error("Yes, but I will go to Mars tomorrow. So only one day with you")
	k.Fatal("Oh no, donot leave me again... faint") // Fatal will call os.Exit(1)
}

sample

Documentation

Overview

beelog project klog

utils.go

Index

Constants

View Source
const (
	Fshortfile = 1 << iota // show filename:lineno
	Fdate
	Ftime
	Fcolor

	Fdatetime = Fdate | Ftime
	Fdevflag  = Fdatetime | Fshortfile | Fcolor // for develop use
	Fstdflag  = Fdatetime | Fcolor
)

Variables

View Source
var (
	DevLog = NewLogger(os.Stdout, "").SetFlags(Fdevflag).SetLevel(LDebug)
	StdLog = NewLogger(os.Stderr, "").SetFlags(Fstdflag).SetLevel(LInfo)
)

Functions

This section is empty.

Types

type Level

type Level int
const (
	LDebug Level = iota
	LInfo
	LWarning
	LError
	LFatal
)

type Logger

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

func NewFileLogger

func NewFileLogger(filename string) (log *Logger, err error)

Default LogLevel Debug

func NewLogger

func NewLogger(out io.Writer, prefix ...string) *Logger

default level is debug

func (*Logger) Debug

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

func (*Logger) Debugf

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

func (*Logger) Error

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

func (*Logger) Errorf

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

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

func (*Logger) Fatalf

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

func (*Logger) Flags

func (l *Logger) Flags() int

get logger flags

func (*Logger) Info

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

func (*Logger) Infof

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

func (*Logger) Level

func (l *Logger) Level() Level

get current level.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flag int) *Logger

set flags to change klog output style

func (*Logger) SetLevel

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

set output level. L[Debug|Warning...]

func (*Logger) Warn

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

func (*Logger) Warnf

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

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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