dlog

package
v0.0.0-...-5f7c8af Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 5 Imported by: 0

README

daily.dlog (v4)

Dlog is a simplest form of leveled logger based on standard log.Logger.

Usage

New

Without creating an instance

package main

import "github.com/orangenumber/daily/dlog/v4"

func main() {
	dlog.Print("hello1")     // hello1
	dlog.Info("hello2")      // hello2
	dlog.Infof("hello%d", 3) // hello3
}

With creating an instance

package main

import "github.com/orangenumber/daily/dlog/v4"

func main() {
	l := dlog.New()
	l.Print(dlog.C_INFO, "hello") // 17:54:13 hello
	l.Info("test") // 17:54:13 test
}
Format
package main

import "github.com/orangenumber/daily/dlog/v4"

func main() {
	// hello
	// hello my name is gon
	dlog.Print("hello")
	dlog.Printf("hello my name is %s", "gon")

	// sup
	// name is gon
	dlog.SetPrefix("test1.")
	dlog.Print("sup")
	dlog.Printf("name is %s", "gon")

	// test2.hey
	// test2.call me gon
	dlog.SetPrefix("test2.")
	dlog.SetFormat(dlog.F_PREFIX)
	dlog.Print("hey")
	dlog.Printf("call me %s", "gon")


	// 17:45:16.922084 test3.hey
	// 17:45:16.922195 test3.call me gon
	dlog.SetPrefix("test3.")
	dlog.SetFormat(dlog.F_PREFIX, dlog.F_MICROSECONDS)
	dlog.Print("hey")
	dlog.Printf("call me %s", "gon")
}
Category Filtering

Many other loggers called a level, but dlog is calling it a category. All the built-in categories are available with a prefix dlog.C_.

package main

import (
	"github.com/orangenumber/daily/dlog/v4"
)

func main() {
	l := dlog.New() // create instance
	l.SetFilter(dlog.C_API, dlog.C_BACK) // create filter
	l.Print(dlog.C_API|dlog.C_FRONT, "API+Front ex")
	l.Print(dlog.C_WARN|dlog.C_API, "Warn+API ex")
	l.Print(dlog.C_WARN|dlog.C_BACK, "Warn+Back ex")
	l.Printf(dlog.C_WARN|dlog.C_FRONT, "Warn+Front: [%s]", "warning code 123")
}
Custom Category

Category, unlike level, supports multiple different types together. For instance, ErrSauce, ErrWing, ErrOrder are the error codes, BadCustom, GoodCustomer are categories, HQ, Branch1, Branch2 are locations. Create whichever you want with uint64 just like the example below.

package main

import "github.com/orangenumber/daily/dlog/v4"

const (
	ErrSauce uint64 = 1 << iota
	ErrWing
	ErrOrder
	BadCustomer
	GoodCustomer
	HQ
	Branch1
	Branch2
)

func main() {
	l := dlog.New()

	// ============================== EX 1: ALL
	// 17:59:57 order1
	// 17:59:57 order2
	// 17:59:57 err3
	l.Print(BadCustomer|HQ, "order1")
	l.Print(GoodCustomer|Branch1|ErrOrder, "order2")
	l.Print(HQ|Branch1|ErrWing, "err3")

	// ============================== EX 2: Only from HQ
	// 18:00:35 order1
	// 18:00:35 err3
	l.SetFilter(HQ)
	l.Print(BadCustomer|HQ, "order1")
	l.Print(GoodCustomer|Branch1|ErrOrder, "order2")
	l.Print(HQ|Branch1|ErrWing, "err3")

	// ============================== EX 3: All errors
	// 18:01:43 order2
	// 18:01:43 err3
	l.SetFilter(ErrWing, ErrOrder, ErrSauce) 
	l.Print(BadCustomer|HQ, "order1")
	l.Print(GoodCustomer|Branch1|ErrOrder, "order2")
	l.Print(HQ|Branch1|ErrWing, "err3")
}

Documentation

Index

Constants

View Source
const (
	// FLAG FORMAT
	F_ALL  FormatFlag = ^FormatFlag(0)
	F_NONE FormatFlag = 0
	F_DATE FormatFlag = 1 << iota
	F_TIME
	F_MICROSECONDS
	F_UTC
	F_PREFIX

	// FLAG CATEGORY
	C_ALL   uint64 = ^uint64(0)
	C_NONE  uint64 = 0
	C_DEBUG uint64 = 1 << iota
	C_INFO
	C_WARN
	C_ERROR
	C_FATAL
	C_PANIC
	C_SYSTEM
	C_IO
	C_NET
	C_SERVICE
	C_REQ // (service) SEND the request
	C_RES // (service) RECEIVEd request and responsed
	C_TIMED
	C_API
	C_BACK
	C_FRONT
	C_GLOBAL
)

Variables

View Source
var Discard io.Writer = devNull(0)

Functions

func Debug

func Debug(s string)

func Debugf

func Debugf(f string, v ...interface{})

func Error

func Error(s string)

func Errorf

func Errorf(f string, v ...interface{})

func Fatal

func Fatal(s string)

func Fatalf

func Fatalf(format string, v ...interface{})

func Info

func Info(s string)

func Infof

func Infof(f string, v ...interface{})

func NewPrint

func NewPrint(flagCat uint64) func(string)

func NewPrintf

func NewPrintf(flagCat uint64) func(string, ...interface{})

func NewPrintln

func NewPrintln(flagCat uint64) func(...interface{})

func NewWriter

func NewWriter(flag uint64, prefix string) io.Writer

func Panic

func Panic(s string)

func Panicf

func Panicf(format string, v ...interface{})

func Print

func Print(s string)

func Printf

func Printf(format string, v ...interface{})

func Println

func Println(v ...interface{})

func SetFilter

func SetFilter(flagCat uint64)

func SetFormat

func SetFormat(flagFmt ...FormatFlag)

func SetOutput

func SetOutput(w io.Writer)

func SetPrefix

func SetPrefix(prefix string)

func Warn

func Warn(s string)

func Warnf

func Warnf(f string, v ...interface{})

Types

type Dlogger

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

func New

func New(opts ...Opt) *Dlogger

func (*Dlogger) Debug

func (l *Dlogger) Debug(s string)

==================================================================== IFACE

func (*Dlogger) Debugf

func (l *Dlogger) Debugf(f string, v ...interface{})

func (*Dlogger) Error

func (l *Dlogger) Error(s string)

func (*Dlogger) Errorf

func (l *Dlogger) Errorf(f string, v ...interface{})

func (*Dlogger) Fatal

func (l *Dlogger) Fatal(s string)

==================================================================== FATAL

func (*Dlogger) Fatalf

func (l *Dlogger) Fatalf(format string, v ...interface{})

func (*Dlogger) Info

func (l *Dlogger) Info(s string)

func (*Dlogger) Infof

func (l *Dlogger) Infof(f string, v ...interface{})

func (*Dlogger) NewPrint

func (l *Dlogger) NewPrint(flagCat uint64) func(string)

==================================================================== PRINT FUNC

func (*Dlogger) NewPrintf

func (l *Dlogger) NewPrintf(flagCat uint64) func(string, ...interface{})

func (*Dlogger) NewPrintln

func (l *Dlogger) NewPrintln(flagCat uint64) func(...interface{})

func (*Dlogger) NewWriter

func (l *Dlogger) NewWriter(flag uint64, prefix string) io.Writer

func (*Dlogger) Output

func (l *Dlogger) Output(flagCat uint64, s string) error

func (*Dlogger) Outputb

func (l *Dlogger) Outputb(flagCat uint64, b []byte) error

Outputb is for exported writer as interface uses func([]byges)(int,error)

func (*Dlogger) Panic

func (l *Dlogger) Panic(s string)

==================================================================== PANIC

func (*Dlogger) Panicf

func (l *Dlogger) Panicf(format string, v ...interface{})

func (*Dlogger) Prefix

func (l *Dlogger) Prefix() string

==================================================================== PREFIX

func (*Dlogger) Print

func (l *Dlogger) Print(flagCat uint64, s string)

==================================================================== PRINT

func (*Dlogger) Printf

func (l *Dlogger) Printf(flagCat uint64, format string, v ...interface{})

func (*Dlogger) Println

func (l *Dlogger) Println(flagCat uint64, v ...interface{})

func (*Dlogger) SetAltOutput

func (l *Dlogger) SetAltOutput(fnAltOut func(uint64, string) error)

func (*Dlogger) SetFilter

func (l *Dlogger) SetFilter(category ...uint64)

func (*Dlogger) SetFormat

func (l *Dlogger) SetFormat(flagFmt ...FormatFlag)

==================================================================== FLAG

func (*Dlogger) SetOutput

func (l *Dlogger) SetOutput(w io.Writer)

func (*Dlogger) SetPrefix

func (l *Dlogger) SetPrefix(prefix string)

func (*Dlogger) Warn

func (l *Dlogger) Warn(s string)

func (*Dlogger) Warnf

func (l *Dlogger) Warnf(f string, v ...interface{})

func (*Dlogger) Writer

func (l *Dlogger) Writer() io.Writer

==================================================================== WRITER

type FormatFlag

type FormatFlag int

type LogWriter

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

==================================================================== WRITER

func (*LogWriter) Write

func (dw *LogWriter) Write(p []byte) (n int, err error)

type LogWriterPrefix

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

==================================================================== WRITER: PREFIX

func (*LogWriterPrefix) Write

func (dw *LogWriterPrefix) Write(p []byte) (n int, err error)

type Opt

type Opt func(*Dlogger)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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