log

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomLogger

type CustomLogger interface {
	Fatal(err error)
	Error(err error)
	Warn(err error)
	Info(err error)
	Debug(err error)
}

CustomLogger interface for custom logging implementations

type DefaultLogger

type DefaultLogger struct {
	// contains filtered or unexported fields
}

DefaultLogger default logging controller

func NewDefaultLogger

func NewDefaultLogger(level Level, writer io.Writer) (d *DefaultLogger)

NewDefaultLogger constructor

func (*DefaultLogger) Debug

func (l *DefaultLogger) Debug(err error)

Debug logging level

Example
package main

import (
	"fmt"
	"os"

	"github.com/ao-concepts/core/pkg/log"
)

func main() {
	l := log.NewDefaultLogger(log.Debug, os.Stdout)

	l.Debug(fmt.Errorf("debug"))
	l.Info(fmt.Errorf("info"))
	l.Warn(fmt.Errorf("warn"))
	l.Error(fmt.Errorf("error"))
}
Output:

{"level":"debug","error":"debug","message":"debug"}
{"level":"info","error":"info","message":"info"}
{"level":"warn","error":"warn","message":"warn"}
{"level":"error","error":"error","message":"error"}
Example (Uninitialized)
package main

import (
	"fmt"

	"github.com/ao-concepts/core/pkg/log"
)

func main() {
	l := log.DefaultLogger{}

	l.Debug(fmt.Errorf("debug"))
	l.Info(fmt.Errorf("info"))
	l.Warn(fmt.Errorf("warn"))
	l.Error(fmt.Errorf("error"))
}
Output:

func (*DefaultLogger) Error

func (l *DefaultLogger) Error(err error)

Error logging level

Example
package main

import (
	"fmt"
	"os"

	"github.com/ao-concepts/core/pkg/log"
)

func main() {
	l := log.NewDefaultLogger(log.Error, os.Stdout)

	l.Debug(fmt.Errorf("debug"))
	l.Info(fmt.Errorf("info"))
	l.Warn(fmt.Errorf("warn"))
	l.Error(fmt.Errorf("error"))
}
Output:

{"level":"error","error":"error","message":"error"}

func (*DefaultLogger) Fatal

func (l *DefaultLogger) Fatal(err error)

Fatal logging level

Example
package main

import (
	"fmt"
	"os"

	"github.com/ao-concepts/core/pkg/log"
)

func main() {
	l := log.NewDefaultLogger(log.Fatal, os.Stdout)

	l.Debug(fmt.Errorf("debug"))
	l.Info(fmt.Errorf("info"))
	l.Warn(fmt.Errorf("warn"))
	l.Error(fmt.Errorf("error"))
}
Output:

func (*DefaultLogger) Info

func (l *DefaultLogger) Info(err error)

Info logging level

Example
package main

import (
	"fmt"
	"os"

	"github.com/ao-concepts/core/pkg/log"
)

func main() {
	l := log.NewDefaultLogger(log.Info, os.Stdout)

	l.Debug(fmt.Errorf("debug"))
	l.Info(fmt.Errorf("info"))
	l.Warn(fmt.Errorf("warn"))
	l.Error(fmt.Errorf("error"))
}
Output:

{"level":"info","error":"info","message":"info"}
{"level":"warn","error":"warn","message":"warn"}
{"level":"error","error":"error","message":"error"}

func (*DefaultLogger) Warn

func (l *DefaultLogger) Warn(err error)

Warn logging level

Example
package main

import (
	"fmt"
	"os"

	"github.com/ao-concepts/core/pkg/log"
)

func main() {
	l := log.NewDefaultLogger(log.Warn, os.Stdout)

	l.Debug(fmt.Errorf("debug"))
	l.Info(fmt.Errorf("info"))
	l.Warn(fmt.Errorf("warn"))
	l.Error(fmt.Errorf("error"))
}
Output:

{"level":"warn","error":"warn","message":"warn"}
{"level":"error","error":"error","message":"error"}

type Level

type Level uint8

Level level of a logging

const (
	// Debug logging level
	Debug Level = 1
	// Info logging level
	Info Level = 2
	// Warn logging level
	Warn Level = 3
	// Error logging level
	Error Level = 4
	// Fatal logging level
	Fatal Level = 5
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger logging controller

func NewLogger

func NewLogger(level Level, logger CustomLogger) *Logger

NewLogger constructor. Uses the DefaultLogger if the logger parameter is nil.

Example
package main

import (
	"fmt"

	"github.com/ao-concepts/core/pkg/log"
)

func main() {
	l := log.NewLogger(log.Debug, nil)

	l.Debug(fmt.Errorf("debug"))
	l.Info(fmt.Errorf("info"))
	l.Warn(fmt.Errorf("warn"))
	l.Error(fmt.Errorf("error"))
}
Output:

{"level":"debug","error":"debug","message":"debug"}
{"level":"info","error":"info","message":"info"}
{"level":"warn","error":"warn","message":"warn"}
{"level":"error","error":"error","message":"error"}

func (*Logger) CreateGinLoggers

func (l *Logger) CreateGinLoggers() []gin.HandlerFunc

CreateGinLoggers mocks this logger for usage with gin (logging, recovery)

func (*Logger) CreateGormLogger

func (l *Logger) CreateGormLogger() glogger.Interface

CreateGormLogger mocks this logger for usage with gorm

func (*Logger) Debug

func (l *Logger) Debug(err error)

Debug logging level

func (*Logger) Error

func (l *Logger) Error(err error)

Error logging level

func (*Logger) Fatal

func (l *Logger) Fatal(err error)

Fatal logging level

func (*Logger) Info

func (l *Logger) Info(err error)

Info logging level

func (*Logger) Warn

func (l *Logger) Warn(err error)

Warn logging level

Jump to

Keyboard shortcuts

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