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