boillog

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 9 Imported by: 0

README

boillog

Before cooking, one has to boil something.

BoilLog is a Go package that provides a simple, yet flexible, logging library designed to integrate with Go applications. It supports environmental configuration and includes basic performance profiling features.

Features

  • Environmental Configuration: Customize log location, application name, and profiling preference through environment variables.
  • Boilerplate Logging: Simplified logging interface to log messages with minimal setup.
  • Performance Profiling: Optional performance profiling to measure and output the execution time of code blocks.

Installation

To install BoilLog, use go get to retrieve the package:

go get github.com/APoniatowski/boillog

Make sure to import the package with:

import "github.com/APoniatowski/boillog"

Usage

Setting Environment Variables

Set the following environment variables to configure BoilLog:

PROFILER: Set to true to enable performance profiling (default: false).
LOGLOCATION: The directory where log files will be stored (default: /var/log/).
APP_NAME: The name of the log file (default: boiler.log).

Logging Functions

LogIt

Use LogIt to log messages easily. It takes a log function name, log type, and message as parameters:

boillog.LogIt("MyFunction", "INFO", "This is an informative message.")
Logger

Logger is used internally by LogIt but can also be used directly if desired. It performs the actual logging operation:

err := boillog.Logger("MyFunction", "ERROR", "This is an error message.")
if err != nil {
    log.Println("Failed to log message:", err)
}

Profiling

Use TrackTime to measure the execution time of functions for performance analysis:

defer boillog.TrackTime("TaskName", time.Now())
// ... code to profile ...

Contributing

Contributions to BoilLog are welcome. Please submit a pull request or raise an issue for any features or bugs.

License

BoilLog is open-sourced software licensed under the MIT license.

Documentation

Index

Constants

View Source
const (
	FuncKey contextKey = "func"
)

Define constants for the key used

Variables

This section is empty.

Functions

func LogIt

func LogIt(logFunction string, logOutput string, message string)

LogIt Boilerplate funtion that calls Logger, to write logs, and prints it if it fails to write it

func TrackTime

func TrackTime(taskName string, pre time.Time) time.Duration

TrackTime defer this function right at the beginning, to track time from start to finish

Types

This section is empty.

Jump to

Keyboard shortcuts

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