gologger

package module
v1.1.12 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 7 Imported by: 1,355

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/projectdiscovery/gologger"
	"github.com/projectdiscovery/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 projectdiscovery 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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.4

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

Label applies a custom label on the log event

func (*Event) Msg added in v1.1.0

func (e *Event) Msg(message string)

Msg logs a message to the logger

func (*Event) MsgFunc added in v1.1.5

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 added in v1.1.0

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

Msgf logs a printf style message to the logger

func (*Event) Str added in v1.1.0

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

Str adds a string metadata item to the log

func (*Event) TimeStamp added in v1.1.5

func (e *Event) TimeStamp() *Event

TimeStamp adds timestamp to the log event

type Logger added in v1.1.0

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 added in v1.1.0

func (l *Logger) Debug() *Event

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

func (*Logger) Error added in v1.1.0

func (l *Logger) Error() *Event

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

func (*Logger) Fatal added in v1.1.0

func (l *Logger) Fatal() *Event

Fatal exits the program if we encounter a fatal error

func (*Logger) Info added in v1.1.0

func (l *Logger) Info() *Event

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

func (*Logger) Log added in v1.1.0

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

Log logs a message to a logger instance

func (*Logger) Print added in v1.1.0

func (l *Logger) Print() *Event

Print prints a string on screen without any extra labels.

func (*Logger) SetFormatter added in v1.1.0

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

SetFormatter sets the formatter instance for a logger

func (*Logger) SetMaxLevel added in v1.1.0

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

SetMaxLevel sets the max logging level for logger

func (*Logger) SetTimestamp added in v1.1.6

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

SetTimestamp enables/disables automatic timestamp

func (*Logger) SetWriter added in v1.1.0

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

SetWriter sets the writer instance for a logger

func (*Logger) Verbose added in v1.1.0

func (l *Logger) Verbose() *Event

Verbose prints a string only in verbose output mode.

func (*Logger) Warning added in v1.1.0

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