gogger

package module
v0.0.0-...-e904721 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: Apache-2.0 Imports: 6 Imported by: 5

README

Gogger

Golang + Logger is a simple and efficient logging library for Go (Golang) that provides easy-to-use logging functionalities.

Features

  • Simple API for logging at different levels (Info, Warning, Error, Debug)
  • Customizable log format
  • Support for logging to different outputs (console, file, etc.)
  • Lightweight and efficient

Installation

To install Gogger, use go get:

go get github.com/dhyanio/gogger

Usage

Here's a basic example of how to use Gogger:

package main

import (
    "github.com/dhyanio/gogger"
)

func main() {
    log, err := gogger.NewLogger("logfile.log", gogger.INFO)
    if err != nil {
        panic(err)
    }

    log.Info().Str("TaskType", "mytask").Int("EventCount", len(numberOfEvens)).Msg("This is an info message")
    log.Warning.Str("TaskType", "mytask").Int("EventCount", len(numberOfEvens)).Msg("This is an warning message")
    log.Error.Str("TaskType", "mytask").Int("EventCount", len(numberOfEvens)).Msg("This is an error message")
    log.Debug.Str("TaskType", "mytask").Int("EventCount", len(numberOfEvens)).Msg("This is an debug message")
}

Configuration

You can customize the logger by setting different options in the configuration file:

func main() {
    config := gogger.Config{
        Output: "stdout",
        Format: "json",
        Level:  gogger.INFO,
    }

    log, err := gogger.NewLoggerWithConfig(config)
    if err != nil {
        panic(err)
    }
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

Thanks to the Go community for their support and contributions. ❤️

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	OutputPath string   // Path to the log file (stdout for console)
	Level      LogLevel // Log level (DEBUG, INFO, WARNING, ERROR)
	Format     string   // Log format (json, text)
}

Config is the configuration for the logger.

type LogLevel

type LogLevel int

LogLevel is the log level.

const (
	DEBUG LogLevel = iota
	INFO
	WARNING
	ERROR
)

type Logger

type Logger struct {
	zerolog.Logger
	// contains filtered or unexported fields
}

Logger is the logger. It wraps the zerolog logger.

func NewLogger

func NewLogger(outputPath string, level LogLevel) (*Logger, error)

NewLogger creates a new logger with the given output path and log level.

func NewLoggerWithConfig

func NewLoggerWithConfig(config Config) (*Logger, error)

NewLoggerWithConfig creates a new logger with the given configuration.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the logger.

func (*Logger) LogErrorWithStack

func (l *Logger) LogErrorWithStack(err error)

LogErrorWithStack logs an error with stack trace.

func (*Logger) LogStructuredData

func (l *Logger) LogStructuredData(data map[string]interface{})

LogStructuredData logs structured data.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

SetLevel sets the log level.

Jump to

Keyboard shortcuts

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