forked from cshum/imagor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
51 lines (41 loc) · 1.21 KB
/
logging.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
package vips
// #include <glib.h>
// #include "logging.h"
import "C"
// LogLevel log level
type LogLevel int
// LogLevel enum
const (
LogLevelError LogLevel = C.G_LOG_LEVEL_ERROR
LogLevelCritical LogLevel = C.G_LOG_LEVEL_CRITICAL
LogLevelWarning LogLevel = C.G_LOG_LEVEL_WARNING
LogLevelMessage LogLevel = C.G_LOG_LEVEL_MESSAGE
LogLevelInfo LogLevel = C.G_LOG_LEVEL_INFO
LogLevelDebug LogLevel = C.G_LOG_LEVEL_DEBUG
)
var (
currentLoggingHandlerFunction = noopLoggingHandler
currentLoggingVerbosity LogLevel
)
// LoggingHandlerFunction logging handler function
type LoggingHandlerFunction func(messageDomain string, messageLevel LogLevel, message string)
// SetLogging set logging handler and verbosity
func SetLogging(handler LoggingHandlerFunction, verbosity LogLevel) {
if handler != nil {
currentLoggingHandlerFunction = handler
}
currentLoggingVerbosity = verbosity
}
func noopLoggingHandler(_ string, _ LogLevel, _ string) {
}
func log(domain string, level LogLevel, message string) {
if level <= currentLoggingVerbosity {
currentLoggingHandlerFunction(domain, level, message)
}
}
func enableLogging() {
C.set_logging_handler()
}
func disableLogging() {
C.unset_logging_handler()
}