gologger

package module
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 7 Imported by: 0

README

gologger

gologger is a very simple logging package to do structured logging in go.

Use gologger as a library
package main

import (
	"strconv"

	"github.com/khulnasoft-labs/gologger"
	"github.com/khulnasoft-labs/gologger/levels"
)

func main() {
	gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
	//	gologger.DefaultLogger.SetFormatter(&formatter.JSON{})
	gologger.Print().Msgf("\tgologger: sample test\t\n")
	gologger.Info().Str("user", "pdteam").Msg("running simulation program")
	for i := 0; i < 10; i++ {
		gologger.Info().Str("count", strconv.Itoa(i)).Msg("running simulation step...")
	}
	gologger.Debug().Str("state", "running").Msg("planner running")
	gologger.Warning().Str("state", "errored").Str("status", "404").Msg("could not run")
	gologger.Fatal().Msg("bye bye")
}

gologger is made with 🖤 by the khulnasoft-labs team.

Documentation

Overview

Package gologger provides a simple layer for leveled logging in go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

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

Event is a log event to be written with data

func Debug

func Debug() *Event

Debug writes an error message on the screen with the default label

func Error

func Error() *Event

Error writes a error message on the screen with the default label

func Fatal

func Fatal() *Event

Fatal exits the program if we encounter a fatal error

func Info

func Info() *Event

Info writes a info message on the screen with the default label

func Print

func Print() *Event

Print prints a string on stderr without any extra labels.

func Silent

func Silent() *Event

Silent prints a string on stdout without any extra labels.

func Verbose

func Verbose() *Event

Verbose prints a string only in verbose output mode.

func Warning

func Warning() *Event

Warning writes a warning message on the screen with the default label

func (*Event) Label

func (e *Event) Label(label string) *Event

Label applies a custom label on the log event

func (*Event) Msg

func (e *Event) Msg(message string)

Msg logs a message to the logger

func (*Event) MsgFunc

func (e *Event) MsgFunc(messageSupplier func() string)

MsgFunc logs a message with lazy evaluation. Useful when computing the message can be resource heavy.

func (*Event) Msgf

func (e *Event) Msgf(format string, args ...interface{})

Msgf logs a printf style message to the logger

func (*Event) Str

func (e *Event) Str(key, value string) *Event

Str adds a string metadata item to the log

func (*Event) TimeStamp

func (e *Event) TimeStamp() *Event

TimeStamp adds timestamp to the log event

type Logger

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

Logger is a logger for logging structured data in a beautfiul and fast manner.

var (

	// DefaultLogger is the default logging instance
	DefaultLogger *Logger
)

func (*Logger) Debug

func (l *Logger) Debug() *Event

Debug writes an error message on the screen with the default label

func (*Logger) Error

func (l *Logger) Error() *Event

Error writes a error message on the screen with the default label

func (*Logger) Fatal

func (l *Logger) Fatal() *Event

Fatal exits the program if we encounter a fatal error

func (*Logger) Info

func (l *Logger) Info() *Event

Info writes a info message on the screen with the default label

func (*Logger) Log

func (l *Logger) Log(event *Event)

Log logs a message to a logger instance

func (*Logger) Print

func (l *Logger) Print() *Event

Print prints a string on screen without any extra labels.

func (*Logger) SetFormatter

func (l *Logger) SetFormatter(formatter formatter.Formatter)

SetFormatter sets the formatter instance for a logger

func (*Logger) SetMaxLevel

func (l *Logger) SetMaxLevel(level levels.Level)

SetMaxLevel sets the max logging level for logger

func (*Logger) SetTimestamp

func (l *Logger) SetTimestamp(timestamp bool, minLevel levels.Level)

SetTimestamp enables/disables automatic timestamp

func (*Logger) SetWriter

func (l *Logger) SetWriter(writer writer.Writer)

SetWriter sets the writer instance for a logger

func (*Logger) Verbose

func (l *Logger) Verbose() *Event

Verbose prints a string only in verbose output mode.

func (*Logger) Warning

func (l *Logger) Warning() *Event

Warning writes a warning message on the screen with the default label

Directories

Path Synopsis
examples
tee

Jump to

Keyboard shortcuts

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