mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 23:06:30 -05:00
comments
This commit is contained in:
parent
49b270152a
commit
3b45a8d4cc
@ -7,10 +7,12 @@ import (
|
||||
"v2ray.com/core/common/serial"
|
||||
)
|
||||
|
||||
// Message is the interface for all log messages.
|
||||
type Message interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// Handler is the interface for log handler.
|
||||
type Handler interface {
|
||||
Handle(msg Message)
|
||||
}
|
||||
@ -19,11 +21,13 @@ type noOpHandler byte
|
||||
|
||||
func (noOpHandler) Handle(msg Message) {}
|
||||
|
||||
// GeneralMessage is a general log message that can contain all kind of content.
|
||||
type GeneralMessage struct {
|
||||
Severity Severity
|
||||
Content interface{}
|
||||
}
|
||||
|
||||
// String implements Message.
|
||||
func (m *GeneralMessage) String() string {
|
||||
return serial.Concat("[", m.Severity, "]: ", m.Content)
|
||||
}
|
||||
@ -32,6 +36,7 @@ func (s Severity) SevererThan(another Severity) bool {
|
||||
return s <= another
|
||||
}
|
||||
|
||||
// Record writes a message into log stream.
|
||||
func Record(msg Message) {
|
||||
h := (*Handler)(atomic.LoadPointer(&logHandler))
|
||||
(*h).Handle(msg)
|
||||
@ -41,6 +46,7 @@ var (
|
||||
logHandler unsafe.Pointer
|
||||
)
|
||||
|
||||
// RegisterHandler register a new handler as current log handler. Previous registered handler will be discarded.
|
||||
func RegisterHandler(handler Handler) {
|
||||
if handler == nil {
|
||||
panic("Log handler is nil")
|
||||
|
Loading…
Reference in New Issue
Block a user