log

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultOutputs specifies the default logging outputs
	DefaultOutputs = []OutputType{ConsoleOutput}
)

Functions

func AddOutput

func AddOutput(writer io.Writer)

AddOutput adds a new output writer to the logger

func Debug

func Debug(err error)

func Debugf

func Debugf(format string, v ...interface{})

func Err

func Err(err error)

func Errf

func Errf(format string, v ...interface{})

func Fatal

func Fatal(err error)

func Info

func Info(err error)

func Infof

func Infof(format string, v ...interface{})

func Init

func Init(cfg Config) error

Init initializes the logging system with the specified configuration

func InitWithDefaults

func InitWithDefaults(logLevel byte)

InitWithDefaults initializes the logger with default console output

func Log

func Log(text string)

func Panic

func Panic(err error)

func Print

func Print(msg string)

func RemoveOutput

func RemoveOutput(writer io.Writer)

RemoveOutput removes an output writer from the logger

func ToDiscord

func ToDiscord(channel HookChannel, text string) error

func Trace

func Trace(err error)

func Tracef

func Tracef(format string, v ...interface{})

func Warn

func Warn(err error)

func Warnf

func Warnf(format string, v ...interface{})

Types

type AllowedMentions

type AllowedMentions struct {
	Parse *[]string `json:"parse,omitempty"`
	Users *[]string `json:"users,omitempty"`
	Roles *[]string `json:"roles,omitempty"`
}

type Author

type Author struct {
	Name    *string `json:"name,omitempty"`
	Url     *string `json:"url,omitempty"`
	IconUrl *string `json:"icon_url,omitempty"`
}

type Config

type Config struct {
	Level           zerolog.Level
	Outputs         []OutputType
	MongoClient     *mongo.Client // Cliente de MongoDB existente
	MongoDatabase   string
	MongoCollection string
}

Config holds the logging configuration

type Embed

type Embed struct {
	Title       *string    `json:"title,omitempty"`
	Url         *string    `json:"url,omitempty"`
	Description *string    `json:"description,omitempty"`
	Color       *string    `json:"color,omitempty"`
	Author      *Author    `json:"author,omitempty"`
	Fields      *[]Field   `json:"fields,omitempty"`
	Thumbnail   *Thumbnail `json:"thumbnail,omitempty"`
	Image       *Image     `json:"image,omitempty"`
	Footer      *Footer    `json:"footer,omitempty"`
}

type Field

type Field struct {
	Name   *string `json:"name,omitempty"`
	Value  *string `json:"value,omitempty"`
	Inline *bool   `json:"inline,omitempty"`
}
type Footer struct {
	Text    *string `json:"text,omitempty"`
	IconUrl *string `json:"icon_url,omitempty"`
}

type HookChannel

type HookChannel string
var (
	HookChannelNone   HookChannel = ""
	HookChannelPro    HookChannel = HookChannel(os.Getenv("DISCORD_CHANNEL_PRO"))
	HookChannelDemo   HookChannel = HookChannel(os.Getenv("DISCORD_CHANNEL_DEMO"))
	HookChannelODM    HookChannel = HookChannel(os.Getenv("DISCORD_CHANNEL_ODM"))
	HookChannelLog    HookChannel = HookChannel(os.Getenv("DISCORD_CHANNEL_LOG"))
	HookChannelErr    HookChannel = HookChannel(os.Getenv("DISCORD_CHANNEL_ERR"))
	HookChannelAgtech HookChannel = HookChannel(os.Getenv("DISCORD_CHANNEL_AGTECH"))
)

type Image

type Image struct {
	Url *string `json:"url,omitempty"`
}

type LogEntry

type LogEntry struct {
	Level     string    `bson:"level"`
	Type      LogType   `bson:"type"`
	Message   string    `bson:"message"`
	Error     string    `bson:"error,omitempty"`
	Timestamp time.Time `bson:"timestamp"`
	Fields    bson.M    `bson:"fields,omitempty"`
}

LogEntry represents a log entry in MongoDB

type LogType

type LogType string

LogType represents the type of log entry

const (
	// LogTypeSystem represents system logs
	LogTypeSystem LogType = "system"
	// LogTypeAuth represents authentication logs
	LogTypeAuth LogType = "auth"
	// LogTypeAPI represents API access logs
	LogTypeAPI LogType = "api"
)

type Message

type Message struct {
	Username        *string          `json:"username,omitempty"`
	AvatarUrl       *string          `json:"avatar_url,omitempty"`
	Content         *string          `json:"content,omitempty"`
	Embeds          *[]Embed         `json:"embeds,omitempty"`
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
}

type MongoDBLogger

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

func NewMongoDBLogger

func NewMongoDBLogger(client *mongo.Client, database, collection string) *MongoDBLogger

NewMongoDBLogger creates a new MongoDB logger using an existing MongoDB client

func (*MongoDBLogger) Close

func (m *MongoDBLogger) Close() error

Close closes the MongoDB connection

func (*MongoDBLogger) CountLogsByLevel

func (m *MongoDBLogger) CountLogsByLevel(level string, dateStr string) (int64, error)

CountLogsByLevel counts logs filtered by level (case-insensitive)

func (*MongoDBLogger) GetLogs

func (m *MongoDBLogger) GetLogs(filter bson.M, limit int, skip int) ([]LogEntry, error)

GetLogs retrieves log entries from MongoDB with optional filtering

func (*MongoDBLogger) GetLogsByLevel

func (m *MongoDBLogger) GetLogsByLevel(level string, limit int, skip int) ([]LogEntry, error)

GetLogsByLevel retrieves logs filtered by level (case-insensitive)

func (*MongoDBLogger) GetLogsByTimeRange

func (m *MongoDBLogger) GetLogsByTimeRange(start, end time.Time, limit int, skip int) ([]LogEntry, error)

GetLogsByTimeRange retrieves logs within a specific time range

func (*MongoDBLogger) GetLogsByType

func (m *MongoDBLogger) GetLogsByType(logType LogType, limit int, skip int) ([]LogEntry, error)

GetLogsByType retrieves logs filtered by type

func (*MongoDBLogger) Write

func (m *MongoDBLogger) Write(p []byte) (n int, err error)

Write implements io.Writer interface

type OutputType

type OutputType string

OutputType defines the type of logging output

const (
	// ConsoleOutput sends logs to console
	ConsoleOutput OutputType = "console"
	// MongoDBOutput sends logs to MongoDB
	MongoDBOutput OutputType = "mongodb"
)

type Thumbnail

type Thumbnail struct {
	Url *string `json:"url,omitempty"`
}

Jump to

Keyboard shortcuts

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