glog

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 11 Imported by: 0

README

Glog

Glog glugs the log files in a concurrent and thread-safe way.

Simple and easy to implement interfaces to log fast and efficiently

Go CodeQL Go Report Card CodeFactor Maintained Quality Gate Status GoDoc


Features

  • Thread-safe logger
  • Log formatting support
  • Logging in unstructured or structured format (JSON)

Usage

go get github.com/ric-v/glog

simple logger to stdout

package main

import "github.com/ric-v/glog"

func main() {
    defer glog.Cleanup()

    // log the message to the default concurrent logger
    glog.Info("Hello World")
}

json logger to file

package main

import "github.com/ric-v/glog"

func main() {
    logger := glog.JSONGlogger("glogger.log")
    defer logger.Cleanup()

    // log the message to custom json logger
    logger.Info("", "Hello", "World")
}

Benchmarks

Benchmark Iterations Time Size Allocation
BenchmarkJSONGlog 266092 3853 ns/op 2185 B/op 25 allocs/op
BenchmarkUnstructureGlog_log 412342 3054 ns/o 984 B/op 13 allocs/op

Examples

visit examples here

Code.Share.Prosper

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup()

safely close the default logger

func Debug

func Debug(msg ...interface{})

Debug logs the warning message to the file

func Debugf added in v1.1.0

func Debugf(format string, msg ...interface{})

Debug logs the warning message to the file

func Error

func Error(msg ...interface{})

Error logs the error message to the file

func Errorf added in v1.1.0

func Errorf(format string, msg ...interface{})

Error logs the error message to the file

func Info

func Info(msg ...interface{})

Info logs the warning message to the file

func Infof added in v1.1.0

func Infof(format string, msg ...interface{})

Info logs the warning message to the file

func Warn

func Warn(msg ...interface{})

Warn logs the warning message to the file

func Warnf added in v1.1.0

func Warnf(format string, msg ...interface{})

Warn logs the warning message to the file

Types

type Glogger

type Glogger interface {
	Error(...interface{}) // error logger without format
	Warn(...interface{})  // warning logger without format
	Info(...interface{})  // info logger without format
	Debug(...interface{}) // debug logger without format

	Errorf(string, ...interface{}) // error logger with format
	Warnf(string, ...interface{})  // warning logger with format
	Infof(string, ...interface{})  // info logger with format
	Debugf(string, ...interface{}) // debug logger with format

	Cleanup() // safely close the glogger
	// contains filtered or unexported methods
}

Glogger is the interface for controlling logging

func NewDefaultGlogger added in v1.1.0

func NewDefaultGlogger() Glogger

NewDefaultGlogger creates a new Glog object for stdout and options for formatting

func NewJSONGlogger added in v1.1.0

func NewJSONGlogger(filePath string, options ...Options) Glogger

NewJSONGlogger creates a new Glog object with the given file name and options for formatting the log messages. The file is created if it does not exist. The file is opened in append mode. The log messages are queued and written to the file in a separate goroutine. The queue is unbuffered.

func NewUnstructureGlogger added in v1.1.0

func NewUnstructureGlogger(filePath string, options ...Options) Glogger

NewUnstructureGlogger creates a new Glog object with the given file name and options for formatting the log messages. The file is created if it does not exist. The file is opened in append mode. The log messages are queued and written to the file in a separate goroutine. The queue is unbuffered.

type JSONGlog

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

JSONGlog type is the logger data for logging concurrently to file easyjson:skip

func (*JSONGlog) Cleanup

func (g *JSONGlog) Cleanup()

safely close the custom logger

func (*JSONGlog) Debug

func (g *JSONGlog) Debug(msg ...interface{})

Debug logs the warning message to the file

func (*JSONGlog) Debugf added in v1.1.0

func (g *JSONGlog) Debugf(format string, msg ...interface{})

Debug logs the warning message to the file

func (*JSONGlog) Error

func (g *JSONGlog) Error(msg ...interface{})

Error logs the error message to the file

func (*JSONGlog) Errorf added in v1.1.0

func (g *JSONGlog) Errorf(format string, msg ...interface{})

Error logs the error message to the file

func (*JSONGlog) Info

func (g *JSONGlog) Info(msg ...interface{})

Info logs the warning message to the file

func (*JSONGlog) Infof added in v1.1.0

func (g *JSONGlog) Infof(format string, msg ...interface{})

Info logs the warning message to the file

func (*JSONGlog) Warn

func (g *JSONGlog) Warn(msg ...interface{})

Warn logs the warning message to the file

func (*JSONGlog) Warnf added in v1.1.0

func (g *JSONGlog) Warnf(format string, msg ...interface{})

Warn logs the warning message to the file

type LogLevel

type LogLevel string
const (
	ERROR LogLevel = "ERROR"
	INFO  LogLevel = "INFO"
	DEBUG LogLevel = "DEBUG"
	WARN  LogLevel = "WARN"
)

type LoggerJson

type LoggerJson struct {
	Time string                 `json:"time"`
	Type string                 `json:"type"`
	File string                 `json:"file"`
	Line string                 `json:"line"`
	Msg  map[string]interface{} `json:"msg"`
}

easyjson:json

func (LoggerJson) MarshalJSON

func (v LoggerJson) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

type Options

type Options struct {
	Format   string
	Position string
}

Options is a struct for setting the format of the log messages

type UnstructureGlog

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

UnstructureGlog type is the logger data for logging concurrently to file

func (*UnstructureGlog) Cleanup

func (g *UnstructureGlog) Cleanup()

safely close the custom logger

func (*UnstructureGlog) Debug

func (g *UnstructureGlog) Debug(msg ...interface{})

Debug logs the warning message to the file

func (*UnstructureGlog) Debugf added in v1.1.0

func (g *UnstructureGlog) Debugf(format string, msg ...interface{})

Debug logs the warning message to the file

func (*UnstructureGlog) Error

func (g *UnstructureGlog) Error(msg ...interface{})

Error logs the error message to the file

func (*UnstructureGlog) Errorf added in v1.1.0

func (g *UnstructureGlog) Errorf(format string, msg ...interface{})

Error logs the error message to the file

func (*UnstructureGlog) Info

func (g *UnstructureGlog) Info(msg ...interface{})

Info logs the warning message to the file

func (*UnstructureGlog) Infof added in v1.1.0

func (g *UnstructureGlog) Infof(format string, msg ...interface{})

Info logs the warning message to the file

func (*UnstructureGlog) Warn

func (g *UnstructureGlog) Warn(msg ...interface{})

Warn logs the warning message to the file

func (*UnstructureGlog) Warnf added in v1.1.0

func (g *UnstructureGlog) Warnf(format string, msg ...interface{})

Warn logs the warning message to the file

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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