Documentation ¶
Index ¶
- type ExportType
- type LogLevel
- type Logger
- func (opts *Logger) Caller(level ShowCallerLevel)
- func (opts *Logger) Copy() *Logger
- func (opts *Logger) Debug(message string, args ...any) error
- func (opts *Logger) Error(message string, args ...any) error
- func (opts *Logger) Export(exportType ExportType, queryOptions ...QueryOption) (string, error)
- func (opts *Logger) Fatal(e error) error
- func (opts *Logger) Folder(path string)
- func (opts *Logger) Info(message string, args ...any) error
- func (opts *Logger) Inline(inline bool)
- func (opts *Logger) PrintDebug(message string, args ...any) error
- func (opts *Logger) PrintError(message string, args ...any) error
- func (opts *Logger) PrintFatal(e error) error
- func (opts *Logger) PrintInfo(message string, args ...any) error
- func (opts *Logger) PrintLogs(queryOptions ...QueryOption) error
- func (opts *Logger) PrintWarn(message string, args ...any) error
- func (opts *Logger) SetFatal(title, message string)
- func (opts *Logger) SetTags(tags ...string)
- func (opts *Logger) ShowTags(show bool)
- func (opts *Logger) Tags(tags ...string)
- func (opts *Logger) Timestamp(level ShowTimestampLevel)
- func (opts *Logger) Warn(message string, args ...any) error
- type QueryOption
- type ShowCallerLevel
- type ShowTimestampLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExportType ¶
type ExportType int
ExportType represents the type of the export it is used to specify the type of the export to be done the type can be:
- JSON: export the logs in JSON format
- CSV: export the logs in CSV format
- LOG: export the logs in LOG format
const ( JSON ExportType = iota // export the logs in JSON CSV // export the logs in CSV LOG // export the logs in LOG )
type LogLevel ¶
type LogLevel int
LogLevel represents the level of the log
- Debug: used for debugging purposes
- Info: used for informational messages
- Warning: used for warning messages
- Error: used for error messages
- Fatal: used for fatal messages
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger represents the logger configuration structure that holds the configuration options for the logger with the methods to interact with the logger and log messages The logger can be configured with the following options:
- Folder: (string) the folder path to store the logs data (by default it uses the binary folder) to store the database file, otherwise it will use the current working directory
- Inline: (bool) if true the logs will be printed inline, otherwise they will be printed in a block
- Caller: (ShowCallerLevel) the level of caller information to show
- Timestamp: (ShowTimestampLevel) the level of timestamp information to show
- ShowTags: (bool) if true the logger will show the tags in the logs
- Tags: (string) the tags to add to the logs created with this logger
- SetFatal: (string, string) the title and message to show in the fatal error alert when the Fatal method is called
- Copy: creates a copy of the logger with the same configurations
The logger has the following methods to log messages:
- Debug: creates a debug log message in the database (it not will be printed)
- Info: creates an info log message in the database (it not will be printed)
- Warn: creates a warning log message in the database (it not will be printed)
- Error: creates an error log message in the database (it not will be printed)
- Fatal: creates a fatal log message in the database and exits the program (it not will be printed) it will show an alert with the title and message set with SetFatal (only if the error passed is not nil)
- PrintDebug: prints a debug log message in the console (it not will be saved in the database)
- PrintInfo: prints an info log message in the console (it not will be saved in the database)
- PrintWarn: prints a warning log message in the console (it not will be saved in the database)
- PrintError: prints an error log message in the console (it not will be saved in the database)
- PrintFatal: prints a fatal log message in the console and exits the program (it not will be saved in the database) if the error passed is not nil
- PrintLogs: prints the logs in the database based on the query configurations passed
func New ¶
New creates a new logger with the given tags the tags will be added to the logs created with this logger if no tags are passed it will create a logger without tags The new logger will have the following default configurations:
- folderPath: the bynary folder path (if it fails to get the path it will use an empty string)
- showTags: false
- inline: false
- showCaller: ShowCallerFile
- showTimestamp: ShowDateTime
- fatalTitle: "Fatal"
- fatalMessage: "An error occurred, please check the logs for more information"
- tags: the tags passed or an empty slice
Check the Logger struct for more information about the logger configurations and the methods to interact with the logger and log messages
func (*Logger) Caller ¶
func (opts *Logger) Caller(level ShowCallerLevel)
Caller sets the level of caller information to show in the logs based on the level parameter the level can be one of the following:
- ShowCallerFile: shows the file of the caller
- ShowCallerLine: shows the caller file and line
- ShowCallerFunction: shows the caller file, line and function
- HideCaller: hides the caller information
func (*Logger) Debug ¶
Debug creates a debug log message in the database with the message and arguments passed it formats the message with the arguments using fmt.Sprintf The new log is created in the database, but it is not printed if it fails to create the log it will return an error
func (*Logger) Error ¶
Error creates an error log message in the database with the message and arguments passed it formats the message with the arguments using fmt.Sprintf The new log is created in the database, but it is not printed if it fails to create the log it will return an error
func (*Logger) Export ¶
func (opts *Logger) Export(exportType ExportType, queryOptions ...QueryOption) (string, error)
Export exports the logs in the database based on the query options passed to the export type passed the export type defines the format of the exported logs the export type can be one of the following:
- LOG: exports the logs in a .log file
- JSON: exports the logs in a .json file
- CSV: exports the logs in a .csv file
the target folder for the exported file will be the folder path set in the logger
this method returns the path of the exported file and an error if it fails to export the logs
func (*Logger) Fatal ¶
Fatal creates a fatal log message in the database only if the error passed is not nil it uses the error message as the message of the log The new log is created in the database, but it is not printed it will show an alert with the title and message set with SetFatal this method will exit the program with code 1 if it fails to create the log it will return an error
func (*Logger) Folder ¶
Folder sets the folder path to store the logs data Every log created with this logger will be stored in this folder
func (*Logger) Info ¶
Info creates an info log message in the database with the message and arguments passed it formats the message with the arguments using fmt.Sprintf The new log is created in the database, but it is not printed if it fails to create the log it will return an error
func (*Logger) Inline ¶
Inline sets the logger to print the logs inline if the inline parameter is true, otherwise it will print the logs in a block (like cards)
func (*Logger) PrintDebug ¶
PrintDebug prints a debug log message in the console with the message and arguments passed it formats the message with the arguments using fmt.Sprintf The new log is not created in the database if it fails to print the log it will return an error
func (*Logger) PrintError ¶
PrintError prints an error log message in the console with the message and arguments passed it formats the message with the arguments using fmt.Sprintf The new log is not created in the database if it fails to print the log it will return an error
func (*Logger) PrintFatal ¶
PrintFatal prints a fatal log message in the console and exits the program with the message and arguments passed only if the error passed is not nil it formats the message with the arguments using fmt.Sprintf The new log is not created in the database if it fails to print the log it will return an error
func (*Logger) PrintInfo ¶
PrintInfo prints an info log message in the console with the message and arguments passed it formats the message with the arguments using fmt.Sprintf The new log is not created in the database if it fails to print the log it will return an error
func (*Logger) PrintLogs ¶
func (opts *Logger) PrintLogs(queryOptions ...QueryOption) error
PrintLogs prints the logs in the database based on the query options passed if it fails to query the logs it will return an error
func (*Logger) PrintWarn ¶
PrintWarn prints a warning log message in the console with the message and arguments passed it formats the message with the arguments using fmt.Sprintf The new log is not created in the database if it fails to print the log it will return an error
func (*Logger) SetFatal ¶
SetFatal sets the title and message to show in the fatal error alert when the Fatal method is called
func (*Logger) SetTags ¶
SetTags sets the tags to the logger this method replaces the current tags with the new ones
func (*Logger) ShowTags ¶
ShowTags sets the logger to show the tags in the logs if the show parameter is true, otherwise it will hide the tags
func (*Logger) Tags ¶
Tags adds the tags to the logger the tags will be added to the logs created with this logger
func (*Logger) Timestamp ¶
func (opts *Logger) Timestamp(level ShowTimestampLevel)
Timestamp sets the level of timestamp information to show in the logs based on the level parameter the level can be one of the following:
- ShowFullTimestamp: shows the full timestamp with date and time
- ShowDateTime: shows the timestamp with date and time
- ShowTime: shows the timestamp with time only
- HideTimestamp: hides the timestamp
type QueryOption ¶
type ShowCallerLevel ¶
type ShowCallerLevel int
ShowCallerLevel is an enum to define the level of caller information to be shown
const ( HideCaller ShowCallerLevel = iota // hide the caller information ShowCallerFile // show the caller file only main.go ShowCallerLine // show the caller file and line main.go:10 ShowCallerFunction // show the caller file, line and function main.go:10 - main.main )
type ShowTimestampLevel ¶
type ShowTimestampLevel int
ShowTimestampLevel is an enum to define the level of timestamp information to be shown the level can be:
- HideTimestamp: hide the timestamp information
- ShowDate: show the date 2006-01-02
- ShowDateTime: show the date and time 2006-01-02 15:04:05
- ShowFullTimestamp: show the full timestamp Monday 2006-01-02 15:04:05
const ( HideTimestamp ShowTimestampLevel = iota // hide the timestamp information ShowDate // show the date 2006-01-02 ShowDateTime // show the date and time 2006-01-02 15:04:05 ShowFullTimestamp // show the full timestamp Monday 2006-01-02 15:04:05 )