-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
82 lines (71 loc) · 1.92 KB
/
logger.go
File metadata and controls
82 lines (71 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package logger
import (
"github.com/Nutdat/logger/core"
)
// logger is the internal instance of the core.Logger used by this package.
var logger *core.Logger
// init initializes the default logger instance with a log directory.
// It is automatically called when the package is imported.
func init() {
logger = core.NewLogger("./.Nutdat/log/")
}
// Cleanup removes log files older than the specified number of days.
//
// Parameters:
// - days: number of days to keep log files. Older logs will be deleted.
func Cleanup(days int) {
logger.CleanupLogs(days)
}
// Info logs an informational message with the "INFO" level.
//
// Parameters:
// - msg: the message to log.
func Info(msg string) {
logger.LogError("INFO", msg)
}
// Warn logs a warning message with the "WARN" level.
//
// Parameters:
// - msg: the message to log.
func Warn(msg string) {
logger.LogError("WARN", msg)
}
// Error logs an error message with the "ERROR" level.
//
// Parameters:
// - msg: the message to log.
func Error(msg string) {
logger.LogError("ERROR", msg)
}
// Fatal logs a critical error message with the "FATAL" level.
//
// Parameters:
// - msg: the message to log.
func Fatal(msg string) {
logger.LogError("FATAL", msg)
}
// Console prints a custom message directly to the console with a module tag.
//
// Parameters:
// - module: a short identifier (e.g., "SQL", "CACHE") to prefix the message.
// - msg: the message to print.
func Console(module, msg string) {
core.LogtoConsole(module, msg)
}
// LogInit prints an initialization-related message to the console,
// using a dark yellow module tag and dark gray message text.
//
// Parameters:
// - module: name of the module or package being initialized.
func LogInit(module string) {
core.LogInitMessage(module)
}
func PrettyPrintJSON(v interface{}) {
core.PrettyPrintJSON(v)
}
// RecoverAndFlush recovers the error
func RecoverAndFlush() {
if r := recover(); r != nil {
logger.Flush()
}
}