gol

package module
v1.0.4-0...-c34012e Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: MIT Imports: 10 Imported by: 0

README

gol

License

Simple logging utility with a few goodies:

  • Asynchronous (requests don't do disk IOs for logging)
  • Log rotation (gol will create new log file once a configurable size is reached)
  • Purge log files that are older than a configurable number of days
  • (Hopefully) sensible default values for all parameters
  • Easy interface for logging public access (a la Apache Web Server)

Latest version: v1.0.3 (can be imported as a Go module)

Usage

import "github.com/deal/gol"

gol.SetAppLogFolder("/path/to/log/folder")     // Log folder for service log (default /var/log)
gol.SetPublicLogFolder("/path/to/log/folder")  // Log folder for public access log (default /var/log)
gol.SetPublicLogMaxSize(200)  // Maximum size of a log file in KB
gol.SetPublicLogMaxAge(20)    // Max age of a file before it's being purged in days (default 10 days)
gol.LogToStdout(true)         // Also log to stdout  (default true)
gol.ShowLineNumbers(false)    // Show file name and line number (default false)

gol.start()  // Start gol (typically in the init() method of the main file of a service)

gol.SetAppLogLevel(gol.INFO)  // Set the logging level (default INFO)

gol.Debug("my message")   // logs a debug message (async)
gol.Info("my message")    // logs an info message (async)
gol.Warn("my message")    // logs a warning message (async)
gol.Error("my message")   // logs an error message (async)
gol.Fatal("my message")   // *synchronously* logs a fatal message and exit with code 1

gol.Public(myRequest)  // Logs info about the http request and response (Apache web server style)

gol.Stop()  // stops gol (typically during graceful shutdown of the service.)

Log file names

Service log files and public access log files will look like this:

alex@ip-192-168-1-14:~/work/deal/dev5/src/shorty/logs --> ls -alh
-rw-r--r--   1 alex  staff   100MB Aug 17 19:52 APP-LOG-2017-08-18-0
-rw-r--r--   1 alex  staff   100MB Aug 17 19:55 APP-LOG-2017-08-18-1
-rw-r--r--   1 alex  staff   100MB Aug 17 20:05 APP-LOG-2017-08-18-2
-rw-r--r--   1 alex  staff   100MB Aug 17 20:09 PUBLIC-ACCESS-LOG-2017-08-18-0
-rw-r--r--   1 alex  staff   100MB Aug 17 20:12 PUBLIC-ACCESS-LOG-22017-08-18-1
-rw-r--r--   1 alex  staff   100MB Aug 17 20:13 PUBLIC-ACCESS-LOG-22017-08-18-2

Documentation

Index

Constants

View Source
const DEBUG = 0
View Source
const ERROR = 3
View Source
const FATAL = 5
View Source
const INFO = 1
View Source
const NUM_LOGGING_ROUTINES = 5
View Source
const WARN = 2

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

func Error

func Error(v ...interface{})

func Fatal

func Fatal(v ...interface{})

Logs the message synchronously and terminates the app with exit code 1.

func Info

func Info(v ...interface{})

func LogToStdout

func LogToStdout(b bool)

func Public

func Public(req http.Request, statusCode int, contentLength int, duration time.Duration)

func SetAppLogFolder

func SetAppLogFolder(path string)

func SetAppLogLevel

func SetAppLogLevel(level int)

func SetAppLogMaxAge

func SetAppLogMaxAge(age int)

func SetAppLogMaxSize

func SetAppLogMaxSize(size int64)

func SetPublicLogFolder

func SetPublicLogFolder(path string)

func SetPublicLogMaxAge

func SetPublicLogMaxAge(age int)

func SetPublicLogMaxSize

func SetPublicLogMaxSize(size int64)

func ShowLineNumbers

func ShowLineNumbers(b bool)

func Start

func Start() error

func Stop

func Stop()

func Warn

func Warn(v ...interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

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