gologger

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: MIT Imports: 4 Imported by: 1,906

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 lable

func Error

func Error() *Event

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

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 lable

func Print added in v1.1.0

func Print() *Event

Print prints a string on screen without any extra lables.

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 lable

func (*Event) Lable added in v1.1.0

func (e *Event) Lable(lable string) *Event

Lable applies a custom lable on the log event

func (*Event) Msg added in v1.1.0

func (e *Event) Msg(format string)

Msg logs a message to the logger

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

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 lable

func (*Logger) Error added in v1.1.0

func (l *Logger) Error() *Event

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

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 lable

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 lables.

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) 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 lable

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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