log

package module
v0.0.0-...-7523c2d Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2017 License: Apache-2.0 Imports: 10 Imported by: 9

README

Build Status GoDoc Go Report

log

golang log

Example
package main

import (
	"github.com/zc310/log"
)

func main() {
	log.SetPath("/tmp/")
	log.Info("a", 1, 2, []string{"a", "b", "c"})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close closes the all logfile.

func Error

func Error(a ...interface{})

func Errorf

func Errorf(format string, a ...interface{})

func Fatal

func Fatal(a ...interface{})

Fatal is equivalent to l.Print() followed by a call to os.Exit(1).

func Fatalf

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

Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1).

func Info

func Info(a ...interface{})

func Infof

func Infof(format string, a ...interface{})

func Print

func Print(a ...interface{})

func Printf

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

func Rotate

func Rotate()

Rotate closes All files, moves it aside with a timestamp in the name,

func SetDefault

func SetDefault(v Logger)

func SetLevel

func SetLevel(v int)

func SetOutput

func SetOutput(level int, prefix string, info, error io.Writer)

SetOutput sets the output destination for the logger.

func SetPath

func SetPath(s string)

SetPath Set the log save path

Types

type Entry

type Entry struct {
	// Time at which the log entry was created
	Time string `json:"time"`

	// Message passed to  Info,  Error
	Message interface{} `json:"msg"`
}

type Formatter

type Formatter interface {
	Format(*Entry, io.Writer) error
}

type InfoLogger

type InfoLogger interface {
	// Info logs a non-error message.  This is behaviorally akin to fmt.Print.
	Print(a ...interface{})

	// Infof logs a formatted non-error message.
	Printf(format string, a ...interface{})
}

func V

func V(level int) InfoLogger

type JSONFormatter

type JSONFormatter struct{}

func (*JSONFormatter) Format

func (p *JSONFormatter) Format(entry *Entry, w io.Writer) error

type Log

type Log struct {
	Prefix    string
	Level     int
	Formatter Formatter
	// contains filtered or unexported fields
}

func New

func New(level int, prefix string) *Log

func (Log) Error

func (p Log) Error(args ...interface{})

func (Log) Errorf

func (p Log) Errorf(format string, a ...interface{})

func (Log) NewWithPrefix

func (p Log) NewWithPrefix(prefix string) Logger

func (Log) Output

func (p Log) Output(w io.Writer, a ...interface{})

func (Log) Outputf

func (p Log) Outputf(w io.Writer, format string, a ...interface{})

func (Log) Print

func (p Log) Print(a ...interface{})

func (Log) Printf

func (p Log) Printf(format string, a ...interface{})

Printf calls l.Output to print to the logger. Arguments are handled in the manner of fmt.Printf.

func (Log) V

func (p Log) V(level int) InfoLogger

func (*Log) WithFormatter

func (p *Log) WithFormatter(v Formatter) Logger

type Logger

type Logger interface {
	// All Loggers implement InfoLogger.  Calling InfoLogger methods directly on
	// a Logger value is equivalent to calling them on a V(0) InfoLogger.  For
	// example, logger.Info() produces the same result as logger.V(0).Info.
	InfoLogger

	// Error logs a error message.  This is behaviorally akin to fmt.Print.
	Error(args ...interface{})

	// Errorf logs a formatted error message.
	Errorf(format string, args ...interface{})

	// V returns an InfoLogger value for a specific verbosity level.  A higher
	// verbosity level means a log message is less important.
	V(level int) InfoLogger

	// NewWithPrefix returns a Logger which prefixes all messages.
	NewWithPrefix(prefix string) Logger
	WithFormatter(v Formatter) Logger
}

Logger represents the ability to log messages, both errors and not.

func NewWithPrefix

func NewWithPrefix(prefix string) Logger

type TextFormatter

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

func (*TextFormatter) Format

func (p *TextFormatter) Format(entry *Entry, w io.Writer) error

type Write

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

func (Write) Close

func (p Write) Close()

func (Write) Rotate

func (p Write) Rotate()

func (Write) Write

func (p Write) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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