Categorygithub.com/go-labx/lightlog
modulepackage
0.0.3
Repository: https://github.com/go-labx/lightlog.git
Documentation: pkg.go.dev

# README

🚀🚀🚀 lightlog

a lightweight and high-performance logging library for Go.

Install

go get github.com/go-labx/lightlog

Usage

To use lightlog, you need to create a logger object. Here's an example of how to create a logger with default options:

options := &LoggerOptions{
    name:     "mylogger",
    level:    INFO,
    filepath: "/var/log/myapp.log",
}
logger := NewLogger(options)

Once you have a logger object, you can use it to log messages:

logger.Trace("This is a trace message: %s", message)
logger.Debug("This is a debug message: %s", message)
logger.Info("This is an info message: %s", message)
logger.Warn("This is a warning message: %s", message)
logger.Error("This is an error message: %s", message)
logger.Fatal("This is an fatal message: %s", message)

Transport

lightlog provides several transport options for logging messages. By default, lightlog creates a console and file transport for each logger. You can also add your own custom transports.

ConsoleTransport

The ConsoleTransport logs messages to the console. Here's an example of how to create a ConsoleTransport:

transport := NewConsoleTransport("myconsole", INFO)

FileTransport

The FileTransport logs messages to a file. Here's an example of how to create a FileTransport:

transport := NewFileTransport("myfile", INFO, "/var/log/myapp.log")

Custom Transports

You can also create your own custom transports by implementing the ITransport interface. Here's an example of a custom transport:

type MyTransport struct {
    *Transport
    // Add any custom fields here
}

func NewMyTransport(name string, level Level) *MyTransport {
    return &MyTransport{
        Transport: NewTransport(name, level),
        // Initialize any custom fields here
    }
}

func (t *MyTransport) Log(formattedData string, data *LogData) {
    // Implement your logging logic here
}

Log Levels

lightlog provides several log levels that you can use to filter messages. The available log levels are:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL

To set the log level of a logger, you can use the level field of the LoggerOptions struct.

# Packages

No description provided by the author

# Functions

NewConsoleLogger creates a new ConsoleLogger with the given name and level.
NewConsoleTransport creates a new ConsoleTransport instance.
NewFileLogger creates a new FileLogger with the given name, level, and filepath.
NewFileTransport is a constructor function that creates a new instance of FileTransport.
NewLogger creates a new Logger with the given options.
NewLoggerCore creates a new LoggerCore instance.
NewTransport Create a new Transport object.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

ConsoleLogger is a struct that contains a pointer to LoggerCore.
ConsoleTransport is a struct that represents a console transport.
FileLogger is a struct that contains a pointer to LoggerCore.
FileTransport is a struct that represents transport for logging to a file.
No description provided by the author
Logger is a struct that contains a pointer to LoggerCore.
No description provided by the author
LoggerOptions is a struct that contains options for creating a new Logger.
No description provided by the author

# Interfaces

ITransport Define an interface called ITransport with several methods.

# Type aliases

No description provided by the author