package module
v1.2.0 Latest Latest

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

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 4 Imported by: 8



Go Version GoDoc codecov Go Report Card tests MIT license


go get github.com/go-packagist/logger


package main

import (

type CustomLogger struct {

var _ logger.Logger = (*CustomLogger)(nil)

func NewCustomLogger() *CustomLogger {
	c := &CustomLogger{
		Loggerable: func(level logger.Level, s string) {
			fmt.Println(fmt.Sprintf("%s %s: %s", time.Now().Format(time.DateTime), level.UpperString(), s))

	return c

func main() {
	c := NewCustomLogger()

	c.Emergencyf("Emergencyf: %s", "test")
	c.Alertf("Alertf: %s", "test")
	c.Criticalf("Criticalf: %s", "test")
	c.Errorf("Errorf: %s", "test")
	c.Warningf("Warningf: %s", "test")
	c.Noticef("Noticef: %s", "test")
	c.Infof("Infof: %s", "test")
	c.Debugf("Debugf: %s", "test")

	c.Emergency("Emergency: test")
	c.Alert("Alert: test")
	c.Critical("Critical: test")
	c.Error("Error: test")
	c.Warning("Warning: test")
	c.Notice("Notice: test")
	c.Info("Info: test")
	c.Debug("Debug: test")

	c.Log(logger.Emergency, "Log: Emergency: test")

	// Output:
	// 2023-03-28 23:18:13 EMERGENCY: Emergencyf: test
	// 2023-03-28 23:18:13 ALERT: Alertf: test
	// 2023-03-28 23:18:13 CRITICAL: Criticalf: test
	// 2023-03-28 23:18:13 ERROR: Errorf: test
	// 2023-03-28 23:18:13 WARNING: Warningf: test
	// 2023-03-28 23:18:13 NOTICE: Noticef: test
	// 2023-03-28 23:18:13 INFO: Infof: test
	// 2023-03-28 23:18:13 DEBUG: Debugf: test
	// 2023-03-28 23:18:13 EMERGENCY: Emergency: test
	// 2023-03-28 23:18:13 ALERT: Alert: test
	// 2023-03-28 23:18:13 CRITICAL: Critical: test
	// 2023-03-28 23:18:13 ERROR: Error: test
	// 2023-03-28 23:18:13 WARNING: Warning: test
	// 2023-03-28 23:18:13 NOTICE: Notice: test
	// 2023-03-28 23:18:13 INFO: Info: test
	// 2023-03-28 23:18:13 DEBUG: Debug: test
	// 2023-03-28 23:18:13 EMERGENCY: Log: Emergency: test

Built-in Logger

  • logger.NewNullLogger() - do nothing
  • logger.NewPrintLogger() - print to stdout


The MIT License (MIT). Please see License File for more information.




View Source
const (
	// EmergencyString is the emergency log level string
	EmergencyString = "emergency"
	// AlertString is the alert log level string
	AlertString = "alert"
	// CriticalString is the critical log level string
	CriticalString = "critical"
	// ErrorString is the error log level string
	ErrorString = "error"
	// WarningString is the warning log level string
	WarningString = "warning"
	// NoticeString is the notice log level string
	NoticeString = "notice"
	// InfoString is the info log level string
	InfoString = "info"
	// DebugString is the debug log level string
	DebugString = "debug"


This section is empty.


This section is empty.


type Level

type Level int
const (
	// Emergency is the emergency log level
	Emergency Level = iota
	// Alert is the alert log level
	// Critical is the critical log level
	// Error is the error log level
	// Warning is the warning log level
	// Notice is the notice log level
	// Info is the info log level
	// Debug is the debug log level

see https://www.rfc-editor.org/rfc/rfc5424.html

func (Level) Int

func (l Level) Int() int

Int returns the integer representation of the log level

func (Level) LowerString

func (l Level) LowerString() string

func (Level) MarshalJSON added in v1.1.0

func (l Level) MarshalJSON() ([]byte, error)

func (Level) String

func (l Level) String() string

String returns the string representation of the log level

func (*Level) UnmarshalJSON added in v1.2.0

func (l *Level) UnmarshalJSON(data []byte) error

func (Level) UpperString

func (l Level) UpperString() string

type Logger

type Logger interface {
	Emergencyf(format string, args ...interface{})
	Alertf(format string, args ...interface{})
	Criticalf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Noticef(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Debugf(format string, args ...interface{})

	Emergency(message string)
	Alert(message string)
	Critical(message string)
	Error(message string)
	Warning(message string)
	Notice(message string)
	Info(message string)
	Debug(message string)

	Log(level Level, message string)

type Loggerable

type Loggerable func(Level, string)

func (Loggerable) Alert

func (l Loggerable) Alert(message string)

func (Loggerable) Alertf

func (l Loggerable) Alertf(format string, args ...interface{})

func (Loggerable) Critical

func (l Loggerable) Critical(message string)

func (Loggerable) Criticalf

func (l Loggerable) Criticalf(format string, args ...interface{})

func (Loggerable) Debug

func (l Loggerable) Debug(message string)

func (Loggerable) Debugf

func (l Loggerable) Debugf(format string, args ...interface{})

func (Loggerable) Emergency

func (l Loggerable) Emergency(message string)

func (Loggerable) Emergencyf

func (l Loggerable) Emergencyf(format string, args ...interface{})

func (Loggerable) Error

func (l Loggerable) Error(message string)

func (Loggerable) Errorf

func (l Loggerable) Errorf(format string, args ...interface{})

func (Loggerable) Info

func (l Loggerable) Info(message string)

func (Loggerable) Infof

func (l Loggerable) Infof(format string, args ...interface{})

func (Loggerable) Log

func (l Loggerable) Log(level Level, message string)

func (Loggerable) Notice

func (l Loggerable) Notice(message string)

func (Loggerable) Noticef

func (l Loggerable) Noticef(format string, args ...interface{})

func (Loggerable) Warning

func (l Loggerable) Warning(message string)

func (Loggerable) Warningf

func (l Loggerable) Warningf(format string, args ...interface{})

type NullLogger

type NullLogger struct {

func NewNullLogger

func NewNullLogger() *NullLogger

NewNullLogger returns a new NullLogger instance.

type PrintLogger

type PrintLogger struct {

func NewPrintLogger

func NewPrintLogger() *PrintLogger

NewPrintLogger returns a new PrintLogger instance.

Jump to

Keyboard shortcuts

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