logger

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 10 Imported by: 0

README

go-level-logger

Features

  • Dynamically config log level
  • Output debug/info/notice messages to stdout, and output warn/error mssages to stdout/stderr
  • Customize log output

Examples

Basic
package main

import (
    "github.com/hongjundu/go-level-logger"
)

func main() {
    logger.InitLogger(logger.LogLevelDebug)

    logger.Debugf("debug message")
    logger.Infof("info message")
    logger.Noticef("notice message")
    logger.Warnf("warn message")
    logger.Errorf("error message")
}
Customize log output
package main

import (
    "github.com/hongjundu/go-level-logger"
)

func main() {
    logger.Init(logger.LogLevelDebug, "example", "/tmp", 100, 3, 365)

    logger.Debugf("debug message")
    logger.Infof("info message")
    logger.Noticef("notice message")
    logger.Warnf("warn message")
    logger.Errorf("error message")
}
Customize rotate log output (Rotate log at 00:00:00 per day)
package main

import (
    "github.com/hongjundu/go-level-logger"
)

func main() {
    logger.InitRotateLogger(logger.LogLevelDebug, "example", "/tmp", 100, 3, 365, logger.RotateStrategyPerDay)

    logger.Debugf("debug message")
    logger.Infof("info message")
    logger.Noticef("notice message")
    logger.Warnf("warn message")
    logger.Errorf("error message")
}
Customize rotate log output (Rotate log per hour)
package main

import (
    "github.com/hongjundu/go-level-logger"
)

func main() {
    logger.InitRotateLogger(logger.LogLevelDebug, "example", "/tmp", 100, 3, 365, logger.RotateStrategyPerHour)

    logger.Debugf("debug message")
    logger.Infof("info message")
    logger.Noticef("notice message")
    logger.Warnf("warn message")
    logger.Errorf("error message")
}

Documentation

Index

Constants

View Source
const (
	LogLevelDebug = iota
	LogLevelInfo
	LogLevelNotice
	LogLevelWarning
	LogLevelError
)
View Source
const (
	LogLevelDebugTag   = "[DEBUG]"
	LogLevelInfoTag    = "[INFO]"
	LogLevelNoticeTag  = "[NOTICE]"
	LogLevelWarningTag = "[WARN]"
	LogLevelErrorTag   = "[ERROR]"
)
View Source
const (
	RotateStrategyPerHour = iota + 1
	RotateStrategyPerDay
)
View Source
const (
	LogTimeFormat = "2006-01-02 15:04:05.000"
)

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Debugln

func Debugln(v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

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

func Errorln

func Errorln(v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

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

func Fatalln

func Fatalln(v ...interface{})

func Info

func Info(v ...interface{})

func Infof

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

func Infoln

func Infoln(v ...interface{})

func Init

func Init(logLevel int, logFileName string, logFileDir string, maxLogFileSize, maxLogFileBackups, maxLogFileAge int)

func InitLogger

func InitLogger(level int)

func InitLoggerWithOutput

func InitLoggerWithOutput(stdOutput, errOutput io.Writer, level int)

func InitRotateLogger added in v1.0.2

func InitRotateLogger(logLevel int, logFileName string, logFileDir string, maxLogFileSize, maxLogFileBackups, maxLogFileAge int, rotateStrategy int)

func Notice

func Notice(v ...interface{})

func Noticef

func Noticef(format string, v ...interface{})

func Noticeln

func Noticeln(v ...interface{})

func Panic

func Panic(v ...interface{})

func Panicf

func Panicf(format string, v ...interface{})

func Panicln

func Panicln(v ...interface{})

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

func Warnln

func Warnln(v ...interface{})

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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