bugolog

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: GPL-3.0, LGPL-3.0 Imports: 5 Imported by: 0

README

bugolog

A logging wrapper for golang

Installation

go get codeberg.org/mbuttner/bugolog

Usage

Import

import ( . codeberg.org/mbuttner/bugolog )

Configure

Filter messages from the output

SetLogLevel(LogLevel)

Log levels are defined as constants in the module, available log levels are LOG_DBG, LOG_INF, LOG_WRN, LOG_ERR and LOG_FATAL. Messages with a level below the level passed to SetLogLevel will not be printed.

Default is LOG_INF, all messages will be printed except those with level LOG_DEBG.

Add source code references

SetTraceMode(bool)

When trace mode is enabled through a call to SetTraceMode(true), each printed message will contain the source file and line of the logging statement.

Standalone mode

SetStandaloneMode(bool)

The default behavior is to NOT add a timestamp to the logging message, as the expected usage is within a service running under systemd (which already adds a timestamp to the message). For console output during test activities, or in case the application is not running as a systemd service, consider enabling the standalone mode with a call to SetStandaloneMode(true), so that the library adds a timestamp to each printed message.

Log messages, conditional logic

Read the currently selected log level

GetLogLevel()

In case your application needs at some point to find out to what level the filter was set, call GetLogLevel(). For instance, some debugging code should only be executed when the selected log level is "debug", than you will need GetLogLevel()

Log a message

Log(LogLevel, string, ...interface{}) string

The signature of the Log function is close to something like fprintf, with following parameters:

  • LogLevel: should be one of the LOG_* constants, if the passed LogLevel is below the one configured by SetLogLevel (or below the default LOG_INF), the message will be discarded from output
  • string: printf-style format string. Do not add the 'end-of-line', it will be done automatically by the library.
  • ...interface{}: data for substitution to be applied to the format

Misc

Note the special behavior of LogLevel LOG_FATAL: the application will first log the message and than stop. SetLogLevel(LOG_FATAL) will result in a log output reduced to no (if your application completes fine) or 1 message (in case your application reaches the Log(LOG_FATAL ...) statement).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Log

func Log(msgLevel LogLevel, fmtstr string, data ...interface{}) string

Write a line into the message log.

Callers: DO NOT add the CR at the end of the format string, this is done in the function automatically

The function returns the logged string. Usually of no use except for testing

func SetLogLevel

func SetLogLevel(newLevel LogLevel)

change the level for this particular logger

func SetStandaloneMode

func SetStandaloneMode(newTestMode bool)

set to true when not running as a service, so that timestamp is added

func SetTraceMode

func SetTraceMode(newTraceMode bool)

Types

type LogLevel

type LogLevel int
const LOG_DBG LogLevel = 0
const LOG_ERR LogLevel = 3
const LOG_FATAL LogLevel = 4
const LOG_INF LogLevel = 1
const LOG_WRN LogLevel = 2

func GetLogLevel

func GetLogLevel() LogLevel

@return LogLevel the log level currently applied to this logger

Jump to

Keyboard shortcuts

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