Exemplo n.º 1
0
func main() {

	// Default logger
	log.Debug("Debug")
	log.Info("Info")
	log.Notice("Notice")
	log.Warning("Warning")
	log.Error("Error")
	log.Critical("Critical")

	// Custom logger with default handler
	l := log.NewLogger("test")

	l.Debug("Debug")
	l.Info("Info")
	l.Notice("Notice")
	l.Warning("Warning")
	l.Error("Error")
	l.Critical("Critical")

	// Custom logger with custom handler
	l2 := log.NewLogger("test2")
	h := NewMyHandler("!!!")
	h.SetLevel(log.WARNING)
	l2.SetHandler(h)

	l2.Debug("Debug")
	l2.Info("Info")
	l2.Notice("Notice")
	l2.Warning("Warning")
	l2.Error("Error")
	l2.Critical("Critical")
}
Exemplo n.º 2
0
func InitLogger() {
	processName := path.Base(os.Args[0])
	baseName := strings.Replace(processName, ".exe", "", -1)
	logFilename := fmt.Sprintf("%s.log", baseName)

	// Log levels (DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL)

	log = alog.NewLogger(processName)
	log.SetLevel(alog.DEBUG) // forward all messages to handler

	consoleLog := alog.NewWriterHandler(os.Stderr)
	consoleLog.SetFormatter(logFormatter{})
	consoleLog.SetLevel(alog.DEBUG)
	consoleLog.Colorize = true

	fileLog := alog.NewWriterHandler(logFile(logFilename))
	fileLog.SetLevel(alog.NOTICE)
	//log.SetHandler(fileLog)

	multi := alog.NewMultiHandler(consoleLog, fileLog)
	multi.SetFormatter(logFormatter{})

	log.SetHandler(multi)

}
Exemplo n.º 3
0
func New(name string) Logger {
	logger := log.NewLogger(name)
	logger.SetLevel(log.DEBUG) // forward all messages to handler
	logger.SetHandler(DefaultLogHandler)
	return logger
}