log

package module
v0.0.0-...-b61a130 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 14 Imported by: 10

README

tinylog

tinylog is a dead simple, levelable, colorful logging library.

use

package main

import "C"

import (
  log "github.com/chunqian/tinylog"
)

type Tiny struct {
  name   string
  number int
  keys   []int
  dict   map[string]any
}

func main() {
  t := Tiny{
    "tiny",
    100,
    []int{1, 2, 3, 4, 5, 6},
    map[string]any{
      "start": 123,
      "end":   456,
    },
  }

  msg := [6]int8{'H', 'e', 'l', 'l', 'o', '\x00'}
  msg2 := [4]int8{'G', 'o', '!', '\x00'}
  msg3 := [6]C.char{'H', 'e', 'l', 'l', 'o', '\x00'}
  msg4 := [4]C.char{'G', 'o', '!', '\x00'}

  log.Info("Tiny: {}", t)

  log.Debug("Say: {}, {}", "Hello", "Go!")
  log.Warn("Say: {}, {}", "Hello", "Go!")
  log.Info("Say: {}, {}", "Hello", "Go!")
  log.Error("Say: {}, {}", "Hello", "Go!")
  log.Message("Say: {}, {}", &msg[0], &msg2[0])
  log.Message("Say: {}, {}", unsafe.Pointer(&msg3[0]), unsafe.Pointer(&msg4[0]))
  log.Fatal("Say: {}, {}", "Hello", "Go!")
}

output

go build -o stdlog ./test
./stdlog
[INFO] Tiny: main.Tiny{
  name:   "tiny",
  number: 100,
  keys:   {1, 2, 3, 4, 5, 6},
  dict:   {
    "start": int(123),
    "end":   int(456),
  },
}
[DEBUG] Say: Hello, Go!
[WARN] Say: Hello, Go!
[INFO] Say: Hello, Go!
[ERROR] Say: Hello, Go!
[MESSAGE] Say: Hello, Go!
[MESSAGE] Say: Hello, Go!
[FATAL] Say: Hello, Go!

output files

//go:build cronolog

package main

import (
  "os"

  log "github.com/chunqian/tinylog"
)

func init() {
  // create writer to writes message to a set of output files
  getwd, _ := os.Getwd()
  writer, _ := log.NewWriter(getwd + "/logs/%Y/%m/%d/test.log")
  log.SetOutput(writer)
}

go build -tags cronolog -o cronolog ./test
./cronolog

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Prefix     = "[Log]"
	TimeFormat = "06-01-02 15:04:05"

	NonColor           bool
	ShowDepth          bool
	ShowTime           bool
	ShowPrefix         bool
	DefaultCallerDepth = 3
)

Functions

func Debug

func Debug(args ...any)

func Error

func Error(args ...any)

func Fatal

func Fatal(args ...any)

func Info

func Info(args ...any)

func Message

func Message(args ...any)

func Pointer

func Pointer(args ...any)

func Print

func Print(level Level, depth int, addNewline bool, args ...any)

func SetOutput

func SetOutput(writer *Writer) error

func Stack

func Stack() string

func Warn

func Warn(args ...any)

Types

type Level

type Level int
const (
	DEBUG Level = iota
	INFO
	WARNING
	ERROR
	FATAL
	MESSAGE
	POINTER
)

type Writer

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

A Writer writes message to a set of output files.

func NewWriter

func NewWriter(pattern string) (*Writer, error)

New returns a Writer with the given pattern.

func (*Writer) Close

func (c *Writer) Close() error

Close closes file.

func (*Writer) Path

func (c *Writer) Path() string

Path returns the current writing file path.

func (*Writer) Write

func (c *Writer) Write(b []byte) (int, error)

Write writes to the file and rotate files automatically based on current date and time.

Directories

Path Synopsis
Package pretty provides pretty-printing for Go values.
Package pretty provides pretty-printing for Go values.

Jump to

Keyboard shortcuts

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