fileLogger

package module
v0.0.0-...-fdc0c5b Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2015 License: Apache-2.0 Imports: 8 Imported by: 17

README

fileLogger

fileLogger是一个基于Go开发的可自动分割文件进行备份的异步日志库

Build Status Go Walker

Features

  • 日志文件可按文件大小进行备份,可定制文件大小和数量
  • 日志文件可按日期进行备份
  • 两种使用模式:
    • 不同类型log分别写入不同的文件,使用Print(),Printf(),Println()三个方法
    • 不同类型log写入一个文件,但不同LEVEL的日志具有不同的颜色,使用T(),I(),W(),E()等方法,默认日志LEVEL为TRACE

Installation

安装FileLogger使用"go get"命令

go get github.com/aiwuTech/fileLogger

只基于Go标准库,不依赖第三方库

Update

更新FileLogger使用"go get -u"命令

go get -u github.com/aiwuTech/fileLogger

Usage

用法请参考example,持续更新中

API

请参考Go Walker

FAQ

如果使用过程中遇到任何问题,希望主动与aiwuTech团队联系,也可提交Issues,我们会及时解决

License

FileLogger基于 Apache License, Version 2.0.

Documentation

Overview

Package: fileLogger File: fileLogger.go Created by: mint(mint.zhao.chiu@gmail.com)_aiwuTech Useage: DATE: 14-8-23 17:20

Package: fileLogger File: setter.go Created by: mint(mint.zhao.chiu@gmail.com)_aiwuTech Useage: fileLogger settings DATE: 14-8-24 11:14

Package: fileLogger File: util.go Created by: mint(mint.zhao.chiu@gmail.com)_aiwuTech Useage: some useful utils DATE: 14-8-23 17:03

Package: fileLogger File: writer.go Created by: mint(mint.zhao.chiu@gmail.com)_aiwuTech Useage: DATE: 14-8-24 12:40

Index

Constants

View Source
const (
	DATEFORMAT         = "2006-01-02"
	DEFAULT_FILE_COUNT = 10
	DEFAULT_FILE_SIZE  = 50
	DEFAULT_FILE_UNIT  = MB
	DEFAULT_LOG_SCAN   = 300
	DEFAULT_LOG_SEQ    = 5000
	DEFAULT_LOG_LEVEL  = TRACE
)
View Source
const (
	// Bits or'ed together to control what's printed. There is no control over the
	// order they appear (the order listed here) or the format they present (as
	// described in the comments).  A colon appears after these items:
	//	2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
	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
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
)

Copy from go sdk These flags define which text to prefix to each log entry generated by the Logger.

View Source
const (
	DEFAULT_PRINT_INTERVAL = 300
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FileLogger

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

func NewDailyLogger

func NewDailyLogger(fileDir, fileName, prefix string, logScan int64, logSeq int) *FileLogger

NewDailyLogger return a logger split by daily Parameters:

file directory
file name
log's prefix

func NewDefaultLogger

func NewDefaultLogger(fileDir, fileName string) *FileLogger

NewDefaultLogger return a logger split by fileSize by default

func NewSizeLogger

func NewSizeLogger(fileDir, fileName, prefix string, fileCount int, fileSize int64, unit UNIT,
	logScan int64, logSeq int) *FileLogger

NewSizeLogger return a logger split by fileSize Parameters:

file directory
file name
log's prefix
fileCount holds maxCount of bak file
fileSize holds each of bak file's size
unit stands for kb, mb, gb, tb
logScan after a logScan time will check fileLogger isMustSplit, default is 300s

func (*FileLogger) Close

func (f *FileLogger) Close() error

passive to close fileLogger

func (*FileLogger) E

func (f *FileLogger) E(format string, v ...interface{})

same with Error()

func (*FileLogger) Error

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

error log

func (*FileLogger) I

func (f *FileLogger) I(format string, v ...interface{})

same with Info()

func (*FileLogger) Info

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

info log

func (*FileLogger) Print

func (f *FileLogger) Print(v ...interface{})

Print throw logstr to channel to print to the logger. Arguments are handled in the manner of fmt.Print.

func (*FileLogger) Printf

func (f *FileLogger) Printf(format string, v ...interface{})

Printf throw logstr to channel to print to the logger. Arguments are handled in the manner of fmt.Printf.

func (*FileLogger) Println

func (f *FileLogger) Println(v ...interface{})

Println throw logstr to channel to print to the logger. Arguments are handled in the manner of fmt.Println.

func (*FileLogger) SetFlags

func (f *FileLogger) SetFlags(flag int)

SetFlags sets the output flags for the logger.

func (*FileLogger) SetLogConsole

func (f *FileLogger) SetLogConsole(console bool)

SetLogConsole sets whether the log string will print in console, default is false

func (*FileLogger) SetLogLevel

func (f *FileLogger) SetLogLevel(level LEVEL)

SetLogLevel sets the output log's Level: TRACE<INFO<WARN<ERROR<OFF

func (*FileLogger) SetLogScanInterval

func (f *FileLogger) SetLogScanInterval(interval int)

SetLogScanInterval sets the ticker's interval

func (*FileLogger) SetLogSeq

func (f *FileLogger) SetLogSeq(logSeq int)

SetLogSeq sets the logChan's buffer size

func (*FileLogger) SetMaxFileCount

func (f *FileLogger) SetMaxFileCount(count int) int

Change the sizeSplit fileLogger's bak file count

func (*FileLogger) SetMaxFileSize

func (f *FileLogger) SetMaxFileSize(size int64, unit UNIT) int64

Change the sizeSplit fileLogger's single file size

func (*FileLogger) SetPrefix

func (f *FileLogger) SetPrefix(prefix string)

SetPrefix sets the output prefix for the logger.

func (*FileLogger) T

func (f *FileLogger) T(format string, v ...interface{})

same with Trace()

func (*FileLogger) Trace

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

====================================================================================================================== Trace log

func (*FileLogger) W

func (f *FileLogger) W(format string, v ...interface{})

same with Warn()

func (*FileLogger) Warn

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

warning log

type LEVEL

type LEVEL byte
const (
	TRACE LEVEL = iota
	INFO
	WARN
	ERROR
	OFF
)

type SplitType

type SplitType byte
const (
	SplitType_Size SplitType = iota
	SplitType_Daily
)

type UNIT

type UNIT int64
const (
	KB UNIT = 1 << (iota * 10)
	MB
	GB
	TB
)

Directories

Path Synopsis
Package: example File: example.go Created by: mint(mint.zhao.chiu@gmail.com)_aiwuTech Useage: example DATE: 14-8-24 14:08
Package: example File: example.go Created by: mint(mint.zhao.chiu@gmail.com)_aiwuTech Useage: example DATE: 14-8-24 14:08

Jump to

Keyboard shortcuts

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