Documentation
¶
Index ¶
- Constants
- Variables
- func QueueSize() int
- func Service(errorLog string, trafficLog string, criticalLog string)
- func SetNameConventionDayMonthYear(logger *CustomLogger)
- func SetNameConventionMonthYear(logger *CustomLogger)
- func SetNameConventionYear(logger *CustomLogger)
- func Write(logType int, data ...interface{})
- func WritePrint(logType int, data ...interface{})
- type CustomLogger
- type LogType
- type Logger
Constants ¶
const ( //LogError is used to log any sort of error, both internal and external LogError = 0 //LogCritical is used to log any large issues/errors LogCritical = 1 //LogTraffic logs web traffic LogTraffic = 2 //SystemLogIfCreateFail will log to stdout and LogError if the creation of the Logger fails SystemLogIfCreateFail = 0 //PanicIfFileError will panic the program if a error is encountered PanicIfFileError = 1 )
Variables ¶
var ( //Error is used to log any sort of error, both internal and external Error = LogType{0} //Critical is used to log any large issues/errors Critical = LogType{1} //Traffic logs web traffic Traffic = LogType{2} )
Functions ¶
func Service ¶
Service handles the log events and writes them to disk. Leave errorLog blank if you do not want to use it, same applies to any other log
func SetNameConventionDayMonthYear ¶
func SetNameConventionDayMonthYear(logger *CustomLogger)
SetNameConventionDayMonthYear will automatically configure the logger to use this convention, it will set the convention function and the update period
func SetNameConventionMonthYear ¶
func SetNameConventionMonthYear(logger *CustomLogger)
SetNameConventionMonthYear will automatically configure the logger to use this convention, it will set the convention function and the update period
func SetNameConventionYear ¶
func SetNameConventionYear(logger *CustomLogger)
SetNameConventionYear will automatically configure the logger to use this convention, it will set the convention function and the update period
func Write ¶
func Write(logType int, data ...interface{})
Write will sort the event into the correct queue then procress the action as write to disk
func WritePrint ¶
func WritePrint(logType int, data ...interface{})
WritePrint will print the data and send it to Systemlog.Write()
Types ¶
type CustomLogger ¶
type CustomLogger struct {
Path string
//Extention is the file extention; .txt, .json, .log
Extention string
//NameingConvention returns a string which will be used as the filename
NameingConvention func() string
//LineTerminator usually is "\n"
LineTerminator string
//ValueSeperator is inserted after each value in the data array of a write
ValueSeperator string
//ConventionUpdate is how long the logger should wait until it checks the current naming convention and if its time to change the file handle will be changed
ConventionUpdate time.Duration
//ConventionUpdated can be used to backup the old log file after the convention has change
ConventionUpdated func(oldFile string, newFile string)
// contains filtered or unexported fields
}
CustomLogger is heavily customisable logger which allows for complex file naming conventions and backups
func NewCustomLogger ¶
func NewCustomLogger(path string, extention string, bufferSize int) *CustomLogger
NewCustomLogger creates a new custom logger
func (*CustomLogger) Service ¶
func (l *CustomLogger) Service() error
Service will start the logging service
func (*CustomLogger) Write ¶
func (l *CustomLogger) Write(data ...interface{})
Write will add the data to the queue then write to disk
func (*CustomLogger) WriteJSON ¶
func (l *CustomLogger) WriteJSON(object interface{})
WriteJSON will take in a object and serialise it as JSON
func (*CustomLogger) WritePrint ¶
func (l *CustomLogger) WritePrint(data ...interface{})
WritePrint will write the data to the file but also print it to the screen
type LogType ¶
type LogType struct {
// contains filtered or unexported fields
}
LogType is a datatype for determining what logger to use
func (LogType) Write ¶
func (l LogType) Write(data ...interface{})
Write will sort the event into the correct queue then procress the action as write to disk
func (LogType) WritePrint ¶
func (l LogType) WritePrint(data ...interface{})
WritePrint will print the data and send it to Systemlog.Write()
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is used to log to a file
func (*Logger) Write ¶
func (l *Logger) Write(data ...interface{})
Write will queue the data to be written to disk
func (*Logger) WritePrint ¶
func (l *Logger) WritePrint(data ...interface{})
WritePrint will print the data and send it to *Logger.Write()
func (*Logger) WriteString ¶
func (l *Logger) WriteString(data ...interface{})
WriteString will queue the data to be written to disk