log

package module
v0.0.0-...-1f766c8 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: MIT Imports: 8 Imported by: 10

README

structy/log

Build Status A simple to use log system, minimalist but with features for debugging and differentiation of messages

Example

Example

package main

import (
    "fmt"
    "github.com/structy/log"
)

func main() {
    log.Debugln("Debug message")

    log.DebugMode = false
    log.Debugln("Debug message that will be hidden")

    log.Println("Info message")
    log.Warningln("Warning message")
    log.Errorln("Error message")
    log.Fatal("Fatal error message")
    fmt.Println("I will never be printed because of Fatal()")
}

Documentation

Index

Constants

View Source
const (
	MessageLog         MsgType = 0
	Message2Log        MsgType = 1
	WarningLog         MsgType = 2
	DebugLog           MsgType = 3
	ErrorLog           MsgType = 4
	FormattedOut       OutType = 0
	LineOut            OutType = 1
	DefaultMaxLineSize int     = 2000
	DefaultTimeFormat  string  = "2006/01/02 15:04:05"
)

Variables

View Source
var (
	// DebugMode Enable debug mode
	DebugMode bool

	// EnableANSIColors enables ANSI colors, default true
	EnableANSIColors = true

	// MaxLineSize limits the size of the line, if the size
	// exceeds that indicated by MaxLineSize the system cuts
	// the string and adds "..." at the end.
	MaxLineSize = DefaultMaxLineSize

	// TimeFormat defines which pattern will be applied for
	// display time in the logs.
	TimeFormat = DefaultTimeFormat

	// Colors contain color array
	Colors = []string{
		MessageLog:  "\x1b[37m",
		Message2Log: "\x1b[92m",
		WarningLog:  "\x1b[93m",
		DebugLog:    "\x1b[96m",
		ErrorLog:    "\x1b[91m",
	}

	// Prefixes of messages
	Prefixes = []string{
		MessageLog:  "msg",
		Message2Log: "msg",
		WarningLog:  "warning",
		DebugLog:    "debug",
		ErrorLog:    "error",
	}
)

Functions

func AddAdapter

func AddAdapter(name string, adapter AdapterPod)

AddAdapter allows to add an adapter and parameters

func Debugf

func Debugf(msg ...interface{})

Debugf shows debug message on stdout without line break at the end. If debug mode is not active no message is displayed

func Debugln

func Debugln(msg ...interface{})

Debugln shows debug message on stdout with line break at the end. If debug mode is not active no message is displayed

func DefaultAdapter

func DefaultAdapter(m MsgType, o OutType, config map[string]interface{}, msg ...interface{})

DefaultAdapter of log package

func Errorf

func Errorf(msg ...interface{})

Errorf shows formatted error message on stdout without line break at the end.

func Errorln

func Errorln(msg ...interface{})

Errorln message with line break at the end.

func Fatal

func Fatal(msg ...interface{})

Fatal show message with line break at the end and exit to OS.

func HTTPError

func HTTPError(w http.ResponseWriter, code int)

HTTPError write lot to stdout and return json error on http.ResponseWriter with http error code.

func Printf

func Printf(msg ...interface{})

Printf shows formatted message on stdout without line break at the end.

func Println

func Println(msg ...interface{})

Println shows message on stdout with line break at the end.

func RemoveAdapter

func RemoveAdapter(name string)

RemoveAdapter remove the adapter from list

func SetAdapterConfig

func SetAdapterConfig(name string, config map[string]interface{})

SetAdapterConfig allows set new adapter parameters

func Warningf

func Warningf(msg ...interface{})

Warningf shows formatted warning message on stdout without line break at the end.

func Warningln

func Warningln(msg ...interface{})

Warningln shows warning message on stdout with line break at the end.

Types

type AdapterFunc

type AdapterFunc func(m MsgType, o OutType, config map[string]interface{}, msg ...interface{})

AdapterFunc is the type for the function adapter any function that has this signature can be used as an adapter

type AdapterPod

type AdapterPod struct {
	Adapter AdapterFunc
	Config  map[string]interface{}
}

AdapterPod contains the metadata of an adapter

type MsgType

type MsgType uint8

type OutType

type OutType uint8

Directories

Path Synopsis
adapters

Jump to

Keyboard shortcuts

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