creators

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package logtor provides log creators and loggers for various destinations.

It includes implementations for creating logs and logging messages to a Kafka broker, a base log creator, and a central log manager (Logtor) that coordinates multiple log creators.

The package leverages the "sarama" library for Kafka-related functionalities.

Package logtor provides log creators and loggers for various destinations.

It includes implementations for creating logs and logging messages to a file, with options for customizing log formatting and output location.

Index

Constants

View Source
const Broker types.LogCreatorName = "Broker"

Broker is a constant representing the LogCreatorName for the Broker log creator.

View Source
const Console types.LogCreatorName = "Console"

Console is a constant representing the LogCreatorName for the Console log creator.

View Source
const File types.LogCreatorName = "File"

File is a constant representing the LogCreatorName for the File log creator.

Variables

This section is empty.

Functions

func NewBaseCreator

func NewBaseCreator(logName types.LogCreatorName, callDepth int, logPrefix int) (logtor.LogCreator, error)

NewBaseCreator creates a new instance of the BaseCreator.

It initializes a BaseCreator with the specified logName, callDepth, and logPrefix.

Parameters:

  • logName: The type of log creator (e.g., File, Console).
  • callDepth: The call depth to be used in log output.
  • logPrefix: An integer representing log prefix settings.

Returns:

  • *BaseCreator: A pointer to the newly created BaseCreator.
  • error: An error if initialization fails, or nil if successful.

If logName is an empty string, it defaults to Console.

func NewFileCreator

func NewFileCreator(filename string, logName types.LogCreatorName, callDepth int, logPrefix int) (logtor.LogCreator, error)

NewFileCreator creates a new instance of FileCreator, which logs messages to a file.

It initializes a FileCreator with the provided file name, log creator name, call depth, and log prefix.

Parameters:

  • filename: The name of the log file.
  • logName: The name representing the log creator (e.g., File).
  • callDepth: The call depth to be used in log output.
  • logPrefix: An integer representing log prefix settings.

Returns:

  • *FileCreator: A pointer to the newly created FileCreator.
  • error: An error if initialization fails, or nil if successful.

If logName is an empty string, it defaults to File.

Types

type BaseCreator

type BaseCreator struct {
	// contains filtered or unexported fields
}

BaseCreator is a basic implementation of the LogCreator interface. It logs messages with a specified log level, call depth, and log prefix.

func (*BaseCreator) CallDepth

func (br *BaseCreator) CallDepth() int

CallDepth returns the current call depth setting for recording log entries.

Returns:

  • int: The current call depth setting for recording log entries.

func (*BaseCreator) LogIt

func (br *BaseCreator) LogIt(level types.LogLevel, logMessage interface{}) bool

LogIt logs a message with the specified log level using the default call depth.

This method is a convenience wrapper around LogItWithCallDepth, using the call depth configured for the BaseCreator instance.

Parameters:

  • level: The log level for the message (e.g., INFO, DEBUG).
  • logMessage: The message to be logged, which can be of any type.

Returns:

  • bool: Always returns true, indicating the message was successfully logged.

func (*BaseCreator) LogItWithCallDepth

func (br *BaseCreator) LogItWithCallDepth(level types.LogLevel, callDepth int, logMessage interface{}) bool

LogItWithCallDepth logs a message with the specified log level, call depth, and log message.

It formats the log entry with the log level's color, log prefix, and then outputs the log message. The call depth parameter determines how many stack frames to ascend when recording the log entry.

Parameters:

  • level: The log level for the message (e.g., INFO, DEBUG).
  • callDepth: The call depth for recording the log entry.
  • logMessage: The message to be logged, which can be of any type.

Returns:

  • bool: Always returns true, indicating the message was successfully logged.

func (*BaseCreator) LogName

func (br *BaseCreator) LogName() types.LogCreatorName

LogName returns the name of the log creator.

Returns:

  • LogCreatorName: The name of the log creator.

func (*BaseCreator) SetCallDepth

func (br *BaseCreator) SetCallDepth(callDepth int)

SetCallDepth sets the call depth for recording log entries.

This method allows configuring how deep into the call stack the logger should trace when recording log messages. A higher call depth includes more layers of function calls in the log output, providing additional context about the log origin.

Parameters:

  • callDepth: The depth to set for recording log entries.

func (*BaseCreator) Shutdown

func (br *BaseCreator) Shutdown()

Shutdown performs any necessary cleanup or shutdown operations for the log creator.

This method is present to satisfy the LogCreator interface, but it does not perform any actions in the case of the BaseCreator. It is left empty intentionally.

type BrokerCreator

type BrokerCreator struct {
	// contains filtered or unexported fields
}

BrokerCreator is an implementation of the LogCreator interface for logging messages to a Kafka broker.

func NewBrokerCreator

func NewBrokerCreator(brokers []string, topic string, logName types.LogCreatorName, callDepth int, failWriter io.Writer) (*BrokerCreator, error)

NewBrokerCreator creates a new instance of BrokerCreator, which logs messages to a Kafka broker.

It initializes a BrokerCreator with the provided Kafka broker addresses, topic, time zone, log creator name, and call depth.

Parameters:

  • brokers: A list of Kafka broker addresses.
  • topic: The Kafka topic to publish log messages.
  • logName: The name representing the log creator (e.g., Broker).
  • callDepth: The call depth to be used in log output.

Returns:

  • *BrokerCreator: A pointer to the newly created BrokerCreator.
  • error: An error if initialization fails, or nil if successful.

func (*BrokerCreator) CallDepth

func (br *BrokerCreator) CallDepth() int

CallDepth returns the current call depth setting for recording log entries.

Returns:

  • int: The current call depth setting for recording log entries.

func (*BrokerCreator) LogIt

func (br *BrokerCreator) LogIt(level types.LogLevel, logMessage interface{}) bool

LogIt logs a message with the specified log level using the default call depth to the Kafka broker.

This method is a convenience wrapper around LogItWithCallDepth, using the call depth configured for the BrokerCreator instance.

Parameters:

  • level: The log level for the message (e.g., INFO, DEBUG).
  • logMessage: The message to be logged, which can be of any type.

Returns:

  • bool: Always returns true, indicating the message was successfully logged.

func (*BrokerCreator) LogItWithCallDepth

func (br *BrokerCreator) LogItWithCallDepth(level types.LogLevel, callDepth int, logMessage interface{}) bool

LogItWithCallDepth logs a message with the specified log level, call depth, and log message to the Kafka broker.

It formats the log entry with the log level, timestamp, file name, line number, and log message, then sends the formatted JSON message to the Kafka broker.

Parameters:

  • level: The log level for the message (e.g., INFO, DEBUG).
  • callDepth: The call depth for recording the log entry.
  • logMessage: The message to be logged, which can be of any type.

Returns:

  • bool: Always returns true, indicating the message was successfully logged.

func (*BrokerCreator) LogName

func (br *BrokerCreator) LogName() types.LogCreatorName

LogName returns the name of the log creator.

Returns:

  • LogCreatorName: The name of the log creator.

func (*BrokerCreator) SetCallDepth

func (br *BrokerCreator) SetCallDepth(callDepth int)

SetCallDepth sets the call depth for recording log entries.

This method allows configuring how deep into the call stack the logger should trace when recording log messages. A higher call depth includes more layers of function calls in the log output, providing additional context about the log origin.

Parameters:

  • callDepth: The depth to set for recording log entries.

func (*BrokerCreator) Shutdown

func (br *BrokerCreator) Shutdown()

Shutdown gracefully shuts down the BrokerCreator by closing the Kafka producer.

Use this method to perform any necessary cleanup or shutdown operations for the log creator.

type BrokerMessage

type BrokerMessage struct {
	LogLevel   string      `json:"loglevel"`
	Created    string      `json:"created"`
	File       string      `json:"file"`
	Line       int         `json:"line"`
	LogMessage interface{} `json:"log_message"`
}

BrokerMessage represents the structure of log messages to be sent to the Kafka broker.

type FileCreator

type FileCreator struct {
	// contains filtered or unexported fields
}

FileCreator is an implementation of the LogCreator interface for logging messages to a file.

func (*FileCreator) CallDepth

func (fr *FileCreator) CallDepth() int

CallDepth returns the current call depth setting for recording log entries.

Returns:

  • int: The current call depth setting for recording log entries.

func (*FileCreator) LogIt

func (fr *FileCreator) LogIt(level types.LogLevel, logMessage interface{}) bool

LogIt logs a message with the specified log level using the default call depth to the file.

This method is a convenience wrapper around LogItWithCallDepth, using the call depth configured for the FileCreator instance.

Parameters:

  • level: The log level for the message (e.g., INFO, DEBUG).
  • logMessage: The message to be logged, which can be of any type.

Returns:

  • bool: Always returns true, indicating the message was successfully logged.

func (*FileCreator) LogItWithCallDepth

func (fr *FileCreator) LogItWithCallDepth(level types.LogLevel, callDepth int, logMessage interface{}) bool

LogItWithCallDepth logs a message with the specified log level, call depth, and log message to the file.

It formats the log entry with the log level's prefix and then outputs the log message.

Parameters:

  • level: The log level for the message (e.g., INFO, DEBUG).
  • callDepth: The call depth for recording the log entry.
  • logMessage: The message to be logged, which can be of any type.

Returns:

  • bool: Always returns true, indicating the message was successfully logged.

func (*FileCreator) LogName

func (fr *FileCreator) LogName() types.LogCreatorName

LogName returns the name of the log creator.

Returns:

  • LogCreatorName: The name of the log creator.

func (*FileCreator) SetCallDepth

func (fr *FileCreator) SetCallDepth(callDepth int)

SetCallDepth sets the call depth for recording log entries.

This method allows configuring how deep into the call stack the logger should trace when recording log messages. A higher call depth includes more layers of function calls in the log output, providing additional context about the log origin.

Parameters:

  • callDepth: The depth to set for recording log entries.

func (*FileCreator) Shutdown

func (fr *FileCreator) Shutdown()

Shutdown performs any necessary cleanup or shutdown operations for the log creator.

This method is present to satisfy the LogCreator interface, but it does not perform any actions in the case of the FileCreator. It is left empty intentionally.

Jump to

Keyboard shortcuts

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