aboutsummaryrefslogtreecommitdiff
path: root/weed/mq/kafka/protocol/logging.go
blob: ccc4579be1cb09d6f746e5f19f983a06fcd1098d (plain)
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
package protocol

import (
	"log"
	"os"
)

// Logger provides structured logging for Kafka protocol operations
type Logger struct {
	debug   *log.Logger
	info    *log.Logger
	warning *log.Logger
	error   *log.Logger
}

// NewLogger creates a new logger instance
func NewLogger() *Logger {
	return &Logger{
		debug:   log.New(os.Stdout, "[KAFKA-DEBUG] ", log.LstdFlags|log.Lshortfile),
		info:    log.New(os.Stdout, "[KAFKA-INFO] ", log.LstdFlags),
		warning: log.New(os.Stdout, "[KAFKA-WARN] ", log.LstdFlags),
		error:   log.New(os.Stderr, "[KAFKA-ERROR] ", log.LstdFlags|log.Lshortfile),
	}
}

// Debug logs debug messages (only in debug mode)
func (l *Logger) Debug(format string, args ...interface{}) {
	if os.Getenv("KAFKA_DEBUG") != "" {
		l.debug.Printf(format, args...)
	}
}

// Info logs informational messages
func (l *Logger) Info(format string, args ...interface{}) {
	l.info.Printf(format, args...)
}

// Warning logs warning messages
func (l *Logger) Warning(format string, args ...interface{}) {
	l.warning.Printf(format, args...)
}

// Error logs error messages
func (l *Logger) Error(format string, args ...interface{}) {
	l.error.Printf(format, args...)
}

// Global logger instance
var logger = NewLogger()

// Debug logs debug messages using the global logger
func Debug(format string, args ...interface{}) {
	logger.Debug(format, args...)
}

// Info logs informational messages using the global logger
func Info(format string, args ...interface{}) {
	logger.Info(format, args...)
}

// Warning logs warning messages using the global logger
func Warning(format string, args ...interface{}) {
	logger.Warning(format, args...)
}

// Error logs error messages using the global logger
func Error(format string, args ...interface{}) {
	logger.Error(format, args...)
}