glog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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


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")
}

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(format string, msg ...interface{})

Debug logs the warning message to the file

func Error

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

Error logs the error message to the file

func Info

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

Info logs the warning message to the file

func Warn

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

Warn logs the warning message to the file

Types

type Glog

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

Glog type is the logger data for logging concurrently to file

type Glogger

type Glogger interface {
	Error(string, ...interface{})
	Warn(string, ...interface{})
	Info(string, ...interface{})
	Debug(string, ...interface{})

	Cleanup()
	// contains filtered or unexported methods
}

Glogger is the interface for controlling logging

func JSONGlogger

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

JSONGlogger 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 UnstructureGlogger

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

UnstructureGlogger 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 {
	Glog
}

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(format string, msg ...interface{})

Debug logs the warning message to the file

func (*JSONGlog) Error

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

Error logs the error message to the file

func (*JSONGlog) Info

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

Info logs the warning message to the file

func (*JSONGlog) Warn

func (g *JSONGlog) Warn(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) MarshalEasyJSON

func (v LoggerJson) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (LoggerJson) MarshalJSON

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

MarshalJSON supports json.Marshaler interface

func (*LoggerJson) UnmarshalEasyJSON

func (v *LoggerJson) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*LoggerJson) UnmarshalJSON

func (v *LoggerJson) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler 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 {
	Glog
}

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(format string, msg ...interface{})

Debug logs the warning message to the file

func (*UnstructureGlog) Error

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

Error logs the error message to the file

func (*UnstructureGlog) Info

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

Info logs the warning message to the file

func (*UnstructureGlog) Warn

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

Warn logs the warning message to the file

Directories

Path Synopsis
examples
concurrent command
json-log command
simple command

Jump to

Keyboard shortcuts

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