vlog

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 9 Imported by: 45

README

vertex-logger (vlog)

Vertex Logger (or vlog) is a simple logging library for Golang. This library is used in Vertex to log messages to different outputs:

  • stdout
  • stderr
  • text file
  • JSON file

For text and JSON files, the library open a new file every day. This allows to keep a clean history of the logs, without having huge log files for larger projects.

Installation

go get github.com/vertex-center/vlog

Usage

package main

import (
	"errors"

	"github.com/vertex-center/vlog"
)

func main() {
	log := vlog.New(
		// Stdout and stderr.
		vlog.WithOutputStd(),
		// Text file.
		vlog.WithOutputFile("logs", vlog.LogFormatText),
		// JSON file.
		vlog.WithOutputFile("logs", vlog.LogFormatJson),
	)
    defer log.Close()

	log.Debug("message", vlog.String("name", "abc"))
	log.Info("message", vlog.String("name", "abc"))
	log.Warn("message", vlog.String("name", "abc"))
	log.Error(errors.New("message"), vlog.String("name", "abc"))
	log.Request("message", vlog.String("name", "abc"))
}

License

Vertex-Logger is released under the MIT License.

Documentation

Index

Constants

View Source
const (
	LogFormatText = iota
	LogFormatJson
	LogFormatColoredText
)

Variables

This section is empty.

Functions

func WithOutputFile

func WithOutputFile(format LogFormat, dir string) func(l *Logger)

func WithOutputFunc added in v1.0.3

func WithOutputFunc(format LogFormat, fc func(line string)) func(l *Logger)

func WithOutputStd

func WithOutputStd() func(l *Logger)

Types

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

func Any

func Any(key string, value any) KeyValue

func Bool

func Bool(key string, value bool) KeyValue

func Float32

func Float32(key string, value float32) KeyValue

func Float64

func Float64(key string, value float64) KeyValue

func Int

func Int(key string, value int) KeyValue

func Int16

func Int16(key string, value int16) KeyValue

func Int32

func Int32(key string, value int32) KeyValue

func Int64

func Int64(key string, value int64) KeyValue

func Int8

func Int8(key string, value int8) KeyValue

func String

func String(key string, value string) KeyValue

func Uint

func Uint(key string, value uint) KeyValue

func Uint16

func Uint16(key string, value uint16) KeyValue

func Uint32

func Uint32(key string, value uint32) KeyValue

func Uint64

func Uint64(key string, value uint64) KeyValue

func Uint8

func Uint8(key string, value uint8) KeyValue

type Line

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

func (*Line) ToColoredText added in v1.0.3

func (l *Line) ToColoredText() string

func (*Line) ToFormat added in v1.0.3

func (l *Line) ToFormat(format LogFormat) string

func (*Line) ToJson added in v1.0.3

func (l *Line) ToJson() (string, error)

func (*Line) ToText added in v1.0.3

func (l *Line) ToText() string

type LogFormat

type LogFormat int

type Logger

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

func New

func New(opts ...func(l *Logger)) *Logger

func (*Logger) Close

func (l *Logger) Close()

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...KeyValue)

func (*Logger) Error

func (l *Logger) Error(err error, fields ...KeyValue)

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...KeyValue)

func (*Logger) Raw added in v1.0.4

func (l *Logger) Raw(msg string)

func (*Logger) Request

func (l *Logger) Request(msg string, fields ...KeyValue)

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...KeyValue)

type Output

type Output interface {
	// contains filtered or unexported methods
}

type OutputFile

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

type OutputFunc added in v1.0.3

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

type OutputStd

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

type Tag

type Tag string
const (
	LogTagDebug   Tag = "DBG"
	LogTagInfo    Tag = "INF"
	LogTagWarn    Tag = "WRN"
	LogTagError   Tag = "ERR"
	LogTagRequest Tag = "REQ"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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