logs

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 5 Imported by: 0

README

Logs

A minimal logging library for Go.

Example

package main

import (
	"os"

	"github.com/dipakw/logs"
)

func main() {
	logger := logs.New(&logs.Config{
		TagInf: "info : $t |", // Optional (default "inf | $d $t |) // $d = Current date (yyyy-mm-dd) $t = Current time (hh:mm:ss)
		TagWrn: "warn : $t |", // Optional (default "wrn | $d $t |)
		TagErr: "eror : $t |", // Optional (default "err | $d $t |)

		Outs: []*logs.Out{
			{
				Target: os.Stdout,
				Color:  true,
			},
			{
				File:  "./output.log",
				Color: false,
			},
		},
	})

	logger.Inf("Some info")
	logger.Inff("Formated %s", "info")

	logger.Wrn("Some warning")
	logger.Wrnf("Formatted %s", "warn")

	logger.Err("Some error")
	logger.Errf("Formatted %s", "error")
}

Documentation

Index

Constants

View Source
const (
	TAG_INFO  = "inf | $d $t |"
	TAG_ERROR = "err | $d $t |"
	TAG_WARN  = "wrn | $d $t |"

	INFO  = 1
	WARN  = 2
	ERROR = 4
	ALL   = INFO | WARN | ERROR
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	NopOut bool
	Allow  uint8
	Outs   []*Out
	TagInf string
	TagWrn string
	TagErr string
}

type Log

type Log interface {
	Inff(format string, a ...any)
	Wrnf(format string, a ...any)
	Errf(format string, a ...any)
	Inf(a ...any)
	Wrn(a ...any)
	Err(a ...any)
}

func New

func New(conf *Config) Log

type Logger

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

func (*Logger) Err

func (l *Logger) Err(a ...any)

func (*Logger) Errf

func (l *Logger) Errf(format string, a ...any)

func (*Logger) Inf

func (l *Logger) Inf(a ...any)

func (*Logger) Inff

func (l *Logger) Inff(format string, a ...any)

func (*Logger) Wrn

func (l *Logger) Wrn(a ...any)

func (*Logger) Wrnf

func (l *Logger) Wrnf(format string, a ...any)

type Out

type Out struct {
	File   string
	Target *os.File
	Color  bool
}

Jump to

Keyboard shortcuts

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