Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(a ...any)
- func Fatal(a ...any)
- func Fatalf(format string, a ...any)
- func IndentString(s string, n int) string
- func LogsToJSON(logs []Log) []byte
- func LogsToJSONIndented(logs []Log, spaces int) []byte
- func PanicToErr(f func() error) error
- func Print(level LogLevel, a ...any)
- func Printf(level LogLevel, format string, a ...any)
- func RemoveTerminalColors(s string) string
- func Stack() string
- func ToTerminal(out io.Writer) bool
- type Log
- func (l Log) Colored() string
- func (l Log) Date() time.Time
- func (l Log) Extra() string
- func (l Log) Full() string
- func (l Log) FullColored() string
- func (l Log) ID() string
- func (l Log) JSON() []byte
- func (l Log) Level() LogLevel
- func (l Log) LevelMatchAny(levels ...LogLevel) bool
- func (l Log) MarshalJSON() ([]byte, error)
- func (l Log) Match(tags ...string) bool
- func (l Log) MatchAny(tags ...string) bool
- func (l Log) Message() string
- func (l Log) RawExtra() string
- func (l Log) RawMessage() string
- func (l Log) String() string
- func (l Log) Tags() []string
- func (l *Log) UnmarshalJSON(data []byte) error
- type LogLevel
- type Logger
- func (l *Logger) AddLog(level LogLevel, message string, extra string, writeOutput bool)
- func (l *Logger) AddTags(tags ...string)
- func (l *Logger) Clone(out io.Writer, tags ...string) *Logger
- func (l *Logger) Debug(a ...any)
- func (l *Logger) DisableExtras()
- func (l *Logger) DisableMultiLogger()
- func (l *Logger) EnableExtras()
- func (l *Logger) EnableMultiLogger()
- func (l *Logger) JSON() []byte
- func (l *Logger) JSONIndented(spaces int) []byte
- func (l *Logger) Logs() []Log
- func (l *Logger) LogsLevelMatchAny(levels ...LogLevel) []Log
- func (l *Logger) LogsMatch(tags ...string) []Log
- func (l *Logger) LogsMatchAny(tags ...string) []Log
- func (l *Logger) Print(level LogLevel, a ...any)
- func (l *Logger) Printf(level LogLevel, format string, a ...any)
- func (l *Logger) SetParent(parent *Logger)
- func (l *Logger) Write(p []byte) (n int, err error)
- type PanicError
Constants ¶
const ( DEFAULT_COLOR = "\x1b[0m" BLACK_COLOR = "\x1b[30m" DARK_RED_COLOR = "\x1b[31m" DARK_GREEN_COLOR = "\x1b[32m" DARK_YELLOW_COLOR = "\x1b[33m" DARK_BLUE_COLOR = "\x1b[34m" DARK_MAGENTA_COLOR = "\x1b[35m" DARK_CYAN_COLOR = "\x1b[36m" DARK_WHITE_COLOR = "\x1b[37m" BRIGHT_BLACK_COLOR = "\x1b[90m" BRIGHT_RED_COLOR = "\x1b[31m" BRIGHT_GREEN_COLOR = "\x1b[32m" BRIGHT_YELLOW_COLOR = "\x1b[33m" BRIGHT_BLUE_COLOR = "\x1b[34m" BRIGHT_MAGENTA_COLOR = "\x1b[35m" BRIGHT_CYAN_COLOR = "\x1b[36m" WHITE_COLOR = "\x1b[37m" )
Variables ¶
var (
TimeFormat = "2006-01-02 15:04:05.00" // TimeFormat defines which timestamp to use with the logs. It can be modified.
)
Functions ¶
func IndentString ¶
IndentString takes a string and indents every line with the provided number of single spaces
func LogsToJSON ¶ added in v1.1.5
func LogsToJSONIndented ¶ added in v1.1.5
func PanicToErr ¶
CapturePanic is the same as PanicToErr but returns a plain error
func Print ¶
Print creates a Log with the given severity and message; any data after message will be used to populate the extra field of the Log automatically using the built-in function fmt.Sprint(extra...)
func Printf ¶
Printf creates a Log with the given severity; the rest of the arguments is used as the built-in function fmt.Sprintf(format, a...), however if the resulting string contains a line feed, everything after that will be used to populate the extra field of the Log
func RemoveTerminalColors ¶
func Stack ¶
func Stack() string
Stack returns the execution stack. This must be called after a panic (during a recovery) because it strips the first lines where are reported also the recovery functions, returning only the panic-reletate stuff. If this is not desired just use the standard debug.Stack
func ToTerminal ¶
Types ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is the structure that can be will store any log reported with Logger. It keeps the error severity level (see the constants) the date it was created and the message associated with it (probably an error). It also has the optional field "extra" that can be used to store additional information
func (Log) FullColored ¶ added in v1.2.4
func (Log) LevelMatchAny ¶ added in v1.1.4
func (Log) MarshalJSON ¶ added in v1.2.2
func (Log) RawMessage ¶ added in v1.2.2
func (*Log) UnmarshalJSON ¶ added in v1.2.2
type LogLevel ¶
type LogLevel int
LogLevel defines the severity of a Log. See the constants
func (LogLevel) MarshalJSON ¶ added in v1.0.0
func (*LogLevel) UnmarshalJSON ¶ added in v1.0.0
type Logger ¶
Logger is used by the Router and can be used by the user to create logs that are both written to the chosen io.Writer (if any) and saved locally in memory, so that they can be retreived programmatically and used (for example to make a view in a website)
var DefaultLogger *Logger
func (*Logger) AddLog ¶ added in v1.2.0
AddLog appends a log without behing printed out on the Logger output or by any parent in cascade
func (*Logger) DisableExtras ¶ added in v1.1.2
func (l *Logger) DisableExtras()
func (*Logger) DisableMultiLogger ¶ added in v1.2.0
func (l *Logger) DisableMultiLogger()
func (*Logger) EnableExtras ¶ added in v1.1.2
func (l *Logger) EnableExtras()
func (*Logger) EnableMultiLogger ¶ added in v1.2.0
func (l *Logger) EnableMultiLogger()
func (*Logger) JSONIndented ¶ added in v1.0.0
JSON returns the list of logs stored in JSON format (see Log.JSON() method)
func (*Logger) LogsLevelMatchAny ¶ added in v1.1.4
func (*Logger) LogsMatchAny ¶ added in v1.1.4
type PanicError ¶
type PanicError struct {
// contains filtered or unexported fields
}
PanicError is the data used to capture any function returning an error and any generated panic. If Err is set, means that the function returned an error without panicking, instead if PanicErr is set, this means that the function returned prematurely due to a panic: the panic error is set and the stack trace is provided in the relative field
func CapturePanic ¶ added in v1.1.11
func CapturePanic(f func() error) (panicErr *PanicError)
PanicToErr runs any function that returns an error in a panic-controlled environment and converts any panic (if any) into an error. Expecially, the error generated by a panic can be unwrapped to get rid of the stack trace ( or manipulated to separate the error from the stack trace)
func (PanicError) Err ¶
func (p PanicError) Err() error
func (PanicError) Error ¶
func (err PanicError) Error() string
func (PanicError) PanicErr ¶
func (p PanicError) PanicErr() error
func (PanicError) Stack ¶
func (p PanicError) Stack() string
func (PanicError) String ¶ added in v1.1.6
func (err PanicError) String() string
func (PanicError) Unwrap ¶
func (err PanicError) Unwrap() error