forked from Midtrans/midtrans-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
61 lines (48 loc) · 1.67 KB
/
log.go
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
package midtrans
import (
"fmt"
"os"
)
// LogLevel is the logging level used by the Midtrans go library
type LogLevel uint32
const (
// NoLogging sets a logger to not show the messages
NoLogging LogLevel = 0
// LogError sets a logger to show error messages only.
LogError LogLevel = 1
// LogInfo sets a logger to show information messages
LogInfo LogLevel = 2
// LogDebug sets a logger to show informational messages for debugging
LogDebug LogLevel = 3
)
type LoggerInterface interface {
// Error logs a warning message using Printf conventions.
Error(format string, val ...interface{})
// Info logs an informational message using Printf conventions.
Info(format string, val ...interface{})
// Debug logs debug message using Printf conventions.
Debug(format string, val ...interface{})
}
// LoggerImplementation is a logger interface implementation.
// It prints some info, errors message and debug message for debugging to `os.Stderr` and `os.Stdout`
type LoggerImplementation struct {
LogLevel LogLevel
}
// Error : Logs a warning message using Printf conventions.
func (l *LoggerImplementation) Error(format string, val ...interface{}) {
if l.LogLevel >= LogError {
fmt.Fprintf(os.Stderr, "ERROR - "+format+"\n", val...)
}
}
// Info : Logs information message using Printf conventions.
func (l *LoggerImplementation) Info(format string, val ...interface{}) {
if l.LogLevel >= LogInfo {
fmt.Fprintf(os.Stdout, "INFO - "+format+"\n", val...)
}
}
// Debug : Log debug message using Printf conventions.
func (l *LoggerImplementation) Debug(format string, val ...interface{}) {
if l.LogLevel >= LogDebug {
fmt.Fprintf(os.Stdout, "DEBUG - "+format+"\n", val...)
}
}