logger

package module
v0.0.0-...-9b6f8a1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2019 License: MIT Imports: 10 Imported by: 0

README

logger

multi logger support

quick start

go get -u github.com/lwl1989/logger

mysql config interface

GetMysqlDns() string
GetMysqlUser()  string
GetMysqlPw() string
GetMysqlDb() string
GetMysqlTable() string

mongodb config interface

GetMongodbDns() string
GetMongodbPw() string
GetMongodbDb() string
GetMongodbCollection() string

file config interface

GetFilePath() interface{}

get a logger with driver

  1. import lwl1989/logger
  2. code ∨∨
l := GetLogger("driver name", config)
l.Println("save your content")

The Next

  1. Hdfs and Hbase
  2. logger level

Contact me

qq 285753421

email liwenlong0922@163.com

wechat contact me with wechat

Documentation

Index

Constants

View Source
const (
	TypeFile  = "file"
	TypeMgo   = "mongodb"
	TypeMysql = "mysql"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DoLog

type DoLog interface {
	DoWrite(p []byte) (n int, err error)
}

type FileLog

type FileLog struct {
	FilePath  string
	SaveLevel Level
}

func (*FileLog) DoWrite

func (fileLog *FileLog) DoWrite(buf []byte) (n int, err error)

type FileLogConfig

type FileLogConfig interface {
	GetFilePath() interface{}
}

type Level

type Level uint16
const (
	CRITICAL Level = iota
	ERROR
	WARNING
	NOTICE
	INFO
	DEBUG
)

type Log

type Log struct {
	Log DoLog
}

func (*Log) Write

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

rewrite log Write

type MongodbLog

type MongodbLog struct {
	Config     MongodbLogConfig
	Connection *mgo.Session
}

func (*MongodbLog) DoConnection

func (mongodbLog *MongodbLog) DoConnection()

func (*MongodbLog) DoWrite

func (mongodbLog *MongodbLog) DoWrite(buf []byte) (n int, err error)

type MongodbLogConfig

type MongodbLogConfig interface {
	GetMongodbDns() string
	GetMongodbPw() string
	GetMongodbDb() string
	GetMongodbCollection() string
}

type MysqlLog

type MysqlLog struct {
	Config     MysqlLogConfig
	Connection *sql.DB
}

func (*MysqlLog) DoConnection

func (mysqlLog *MysqlLog) DoConnection()

func (*MysqlLog) DoWrite

func (mysqlLog *MysqlLog) DoWrite(buf []byte) (n int, err error)

type MysqlLogConfig

type MysqlLogConfig interface {
	GetMysqlDns() string
	GetMysqlUser() string
	GetMysqlPw() string
	GetMysqlDb() string
	GetMysqlTable() string
}

type TTLog

type TTLog struct {
	*log.Logger
}
var Logger TTLog
var MongodbLogger TTLog
var MysqlLogger TTLog

func GetFileLogger

func GetFileLogger(config FileLogConfig) *TTLog

get a file logger

func GetLogger

func GetLogger(driver string, config interface{}) (*TTLog, error)

*

  • get a log driver with driver name (mysql|file|mongodb)
  • if errs
  • return nil

func GetMongodbLogger

func GetMongodbLogger(config MongodbLogConfig) *TTLog

get a mysql logger

func GetMysqlLogger

func GetMysqlLogger(config MysqlLogConfig) *TTLog

get a mysql logger

func (*TTLog) Println

func (TTLog *TTLog) Println(v ...interface{})

rewrite log Println

func (*TTLog) SetFileLogPath

func (TTLog *TTLog) SetFileLogPath(config FileLogConfig)

*

  • change file path
  • if driver is file driver

func (*TTLog) Sprintf

func (TTLog *TTLog) Sprintf(format string, v ...interface{})

Jump to

Keyboard shortcuts

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