All Projects β†’ apsdehal β†’ Go Logger

apsdehal / Go Logger

Licence: bsd-3-clause
Simple logger for Go programs. Allows custom formats for messages.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Logger

winston-telegram
A Telegram transport for winston
Stars: ✭ 28 (-89.27%)
Mutual labels:  logger, logging-library
Loggaby
πŸ“ A simple, lightweight and customizable logger.
Stars: ✭ 20 (-92.34%)
Mutual labels:  logger, logging-library
beautiful logger
Yet another logger API in Java with beautiful features
Stars: ✭ 60 (-77.01%)
Mutual labels:  logger, logging-library
loggin-js
πŸ“ Customizable and expandable logger for Node.js
Stars: ✭ 20 (-92.34%)
Mutual labels:  logger, logging-library
use-reducer-logger
A very basic logger for the useReducer function in the React Hooks API.
Stars: ✭ 89 (-65.9%)
Mutual labels:  logger, logging-library
l
Cross-platform html/io [L]ogger with simple API.
Stars: ✭ 26 (-90.04%)
Mutual labels:  logger, logging-library
ratlog.js
πŸ€ Ratlog JavaScript library - Application Logging for Rats, Humans and Machines
Stars: ✭ 24 (-90.8%)
Mutual labels:  logger, logging-library
JJSwiftLog
Swift log library for all platform
Stars: ✭ 51 (-80.46%)
Mutual labels:  logger, logging-library
BLogger
An easy to use modern C++14/17 async cross-platform logger which supports custom formatting/patterns, colored output, Unicode, file logging, log rotation & more!
Stars: ✭ 23 (-91.19%)
Mutual labels:  logger, logging-library
Flogs
An Advanced Logging Framework develop in flutter that provides quick & simple logging solution.
Stars: ✭ 158 (-39.46%)
Mutual labels:  logger, logging-library
noodlog
🍜 Parametrized JSON logging library in Golang which lets you obfuscate sensitive data and marshal any kind of content.
Stars: ✭ 42 (-83.91%)
Mutual labels:  logger, logging-library
moesif-nodejs
Moesif Nodejs Middleware Library (formerly Moesif-Express)
Stars: ✭ 36 (-86.21%)
Mutual labels:  logger, logging-library
clue
a extremely high performance log library for android. ι«˜ζ€§θƒ½ηš„Androidζ—₯εΏ—εΊ“
Stars: ✭ 27 (-89.66%)
Mutual labels:  logger, logging-library
sqlite micro logger arduino
Fast and Lean Sqlite database logger for Microcontrollers
Stars: ✭ 128 (-50.96%)
Mutual labels:  logger, logging-library
RxLogs
An Android & Kotlin Reactive Advanced Logging Framework.
Stars: ✭ 12 (-95.4%)
Mutual labels:  logger, logging-library
Simple-Log
dnkpp.github.io/Simple-Log/
Stars: ✭ 13 (-95.02%)
Mutual labels:  logger, logging-library
Timber Elixir
🌲 Great Elixir logging made easy
Stars: ✭ 226 (-13.41%)
Mutual labels:  logger, logging-library
LogDNA-Android-Client
Android client for LogDNA
Stars: ✭ 22 (-91.57%)
Mutual labels:  logger, logging-library
KmLogging
Kotlin multiplatform logging. High performance, composable and simple to use.
Stars: ✭ 21 (-91.95%)
Mutual labels:  logger, logging-library
chronica
Logger framework for Erlang applications
Stars: ✭ 57 (-78.16%)
Mutual labels:  logger, logging-library

go-logger

Build Status GoDoc

A simple go logger for easy logging in your programs. Allows setting custom format for messages.

Preview

Example Output

Install

go get github.com/apsdehal/go-logger

Use go get -u to update the package.

Example

Example program demonstrates how to use the logger. See below for formatting instructions.

package main

import (
	"github.com/apsdehal/go-logger"
	"os"
)

func main () {
	// Get the instance for logger class, "test" is the module name, 1 is used to
	// state if we want coloring
	// Third option is optional and is instance of type io.Writer, defaults to os.Stderr
	log, err := logger.New("test", 1, os.Stdout)
	if err != nil {
		panic(err) // Check for error
	}

	// Critically log critical
	log.Critical("This is Critical!")
	log.CriticalF("%+v", err)
	// You can also use fmt compliant naming scheme such as log.Criticalf, log.Panicf etc
	// with small 'f'
	
	// Debug
	// Since default logging level is Info this won't print anything
	log.Debug("This is Debug!")
	log.DebugF("Here are some numbers: %d %d %f", 10, -3, 3.14)
	// Give the Warning
	log.Warning("This is Warning!")
	log.WarningF("This is Warning!")
	// Show the error
	log.Error("This is Error!")
	log.ErrorF("This is Error!")
	// Notice
	log.Notice("This is Notice!")
	log.NoticeF("%s %s", "This", "is Notice!")
	// Show the info
	log.Info("This is Info!")
	log.InfoF("This is %s!", "Info")

	log.StackAsError("Message before printing stack");

	// Show warning with format
	log.SetFormat("[%{module}] [%{level}] %{message}")
	log.Warning("This is Warning!") // output: "[test] [WARNING] This is Warning!"
	// Also you can set your format as default format for all new loggers
	logger.SetDefaultFormat("%{message}")
	log2, _ := logger.New("pkg", 1, os.Stdout)
	log2.Error("This is Error!") // output: "This is Error!"

	// Use log levels to set your log priority
	log2.SetLogLevel(DebugLevel)
	// This will be printed
	log2.Debug("This is debug!")
	log2.SetLogLevel(WarningLevel)
	// This won't be printed
	log2.Info("This is an error!")
}

Formatting

By default all log messages have format that you can see above (on pic). But you can override the default format and set format that you want.

You can do it for Logger instance (after creating logger) ...

log, _ := logger.New("pkgname", 1)
log.SetFormat(format)

... or for package

logger.SetDefaultFormat(format)

If you do it for package, all existing loggers will print log messages with format that these used already. But all newest loggers (which will be created after changing format for package) will use your specified format.

But anyway after this, you can still set format of message for specific Logger instance.

Format of log message must contains verbs that represent some info about current log entry. Ofc, format can contain not only verbs but also something else (for example text, digits, symbols, etc)

Format verbs:

You can use the following verbs:

%{id}           - means number of current log message
%{module}       - means module name (that you passed to func New())
%{time}			- means current time in format "2006-01-02 15:04:05"
%{time:format}	- means current time in format that you want
					(supports all formats supported by go package "time")
%{level}		- means level name (upper case) of log message ("ERROR", "DEBUG", etc)
%{lvl}			- means first 3 letters of level name (upper case) of log message ("ERR", "DEB", etc)
%{file} 		- means name of file in what you wanna write log
%{filename}		- means the same as %{file}
%{line}			- means line number of file in what you wanna write log
%{message}		- means your log message

Non-existent verbs (like %{nonex-verb} or %{}) will be replaced by an empty string. Invalid verbs (like %{inv-verb) will be treated as plain text.

Tests

Run:

  • go test logger to run test on logger.
  • go test -bench=. for benchmarks.

Thanks

Thanks goes to all go-loggers out there which I used as reference.

Contributors

Following contributors have made major contributions to go-logger:

License

The BSD 3-Clause license, the same as the Go language.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].