logo

package module
v0.0.0-...-644eacd Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: Apache-2.0 Imports: 13 Imported by: 5

README

logo GoDoc

log for go

Getting Started

Install logo package:

go get github.com/Xuyuanp/logo

Usage

package main

import (
    "os"

    "github.com/Xuyuanp/logo"
)

func main() {
    // use default logo
    logo.Info("logo example")

    // new logo with stdout.
    tl := logo.New(logo.LevelDebug, os.Stdout, "", logo.LdefaultFlags)
    tl.Debug("hello %s", "jack")

    // new logo with file.
    f, err := logo.OpenFile("example.log", 0644)
    if err != nil {
        // ...
        return
    }
    defer f.Close()
    fl := logo.New(logo.LevelInfo, f, "", logo.LstdFlags|logo.Llevel|logo.Lshortfile)
    fl.Warning("something wrong")

    // new logo with smtp
    sw, err := logo.NewSMTPWriter(
        "smtp.example.com:465", // smtp addr
        "username",             // username
        "password",             // password
        "TestLogo",             // email subject
        "you@email.com",        // to-list
    )
    if err != nil {
        // ...
        return
    }
    defer sw.Close()
    sl := logo.New(logo.LevelError, sw, "", logo.LstdFlags|logo.Llevel|logo.Lshortfile)
    sl.Error("uncatched exception!")

    // new logo group with all above logos
    l := logo.Group(logo.LevelDebug, tl, fl, sl)
    l.Info("group message")
}

Documentation

Index

Constants

View Source
const (
	Ldate         = 1 << iota     // the date: 2009/01/23
	Ltime                         // the time: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	Llevel                        // the level name: DBUG|INFO|WARN...
	Lcolor                        // colorful message
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
	LdefaultFlags = LstdFlags | Llevel | Lcolor
	LfullFlags    = LdefaultFlags | Lshortfile
)

These flags define which text to prefix to each log entry generated by the Logger.

Variables

This section is empty.

Functions

func Critical

func Critical(format string, args ...interface{})

Critical logs Critical level message

func Debug

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

Debug logs Debug level message.

func Error

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

Error logs Error level message.

func Info

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

Info logs Info level message

func SetupGlobal

func SetupGlobal(logger Logger)

func Warning

func Warning(format string, args ...interface{})

Warning logs Warning level message.

Types

type LogLevel

type LogLevel int

LogLevel defines level of log message.

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarning
	LevelError
	LevelCritical
)

Available LogLevel const, the higher the more importent.

func (LogLevel) String

func (level LogLevel) String() string

String returns friendly level name.

type Logger

type Logger func(depth int, level LogLevel, msg string)

Logger function type

func Group

func Group(lowest LogLevel, Loggers ...Logger) Logger

Group combines multiple Logger interface into a new Logger which outputs all log message into each Logger of provided.

func New

func New(lowest LogLevel, w io.Writer, prefix string, flag int) Logger

New create a new Logger which outputs log message into io.Writer.

func NewStd

func NewStd(lowest LogLevel, prefix string, flags int) Logger

NewStd creates a new Logger using stdout.

func Std

func Std() Logger

Std returns the default global Logger

func (Logger) Critical

func (l Logger) Critical(format string, args ...interface{})

Critical log Critical level message.

func (Logger) Debug

func (l Logger) Debug(format string, args ...interface{})

Debug logs Debug level message.

func (Logger) Error

func (l Logger) Error(format string, args ...interface{})

Error logs Error level message.

func (Logger) Info

func (l Logger) Info(format string, args ...interface{})

Info logs Info level message.

func (Logger) Log

func (l Logger) Log(level LogLevel, format string, args ...interface{})

Log messages using this level.

func (Logger) Output

func (l Logger) Output(depth int, level LogLevel, msg string)

Output writes the output for a logging event. The string s contains the text to print specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. depth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.

func (Logger) Warning

func (l Logger) Warning(format string, args ...interface{})

Warning logs warning level message.

type RotatedFile

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

RotatedFile is a os.File wrapper to log message. All of its methods are goroutine-safe.

func OpenFile

func OpenFile(name string, mode os.FileMode) (*RotatedFile, error)

OpenFile creates a new RotatedFile instance, and open the file.

func (*RotatedFile) Close

func (rf *RotatedFile) Close() error

Close close the inner *os.File if it's not nil.

func (*RotatedFile) Listen

func (rf *RotatedFile) Listen(sig ...os.Signal)

Listen listens the provided signals, if any of these singals was received, reopen the file. This method is used for logrotate and it will block the current goroutine. If you don't call this method, it works as the same as normal *os.File.

func (*RotatedFile) Write

func (rf *RotatedFile) Write(b []byte) (n int, err error)

Write writes data by using the inner *os.File.

type SMTPWriter

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

SMTPWriter struct

func NewSMTPWriter

func NewSMTPWriter(addr, username, password, subject string, to ...string) (*SMTPWriter, error)

NewSMTPWriter create a new SMTPWriter instance.

func (*SMTPWriter) Close

func (sw *SMTPWriter) Close() (err error)

Close quites SMTP client.

func (*SMTPWriter) Write

func (sw *SMTPWriter) Write(d []byte) (n int, err error)

Jump to

Keyboard shortcuts

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