mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-22 23:51:41 +00:00
Some checks are pending
Build and Release for Windows 7 / check-assets (push) Waiting to run
Build and Release for Windows 7 / build (win7-32, 386, windows) (push) Blocked by required conditions
Build and Release for Windows 7 / build (win7-64, amd64, windows) (push) Blocked by required conditions
Build and Release / check-assets (push) Waiting to run
Build and Release / build (386, freebsd, ) (push) Blocked by required conditions
Build and Release / build (386, linux, ) (push) Blocked by required conditions
Build and Release / build (386, openbsd, ) (push) Blocked by required conditions
Build and Release / build (386, windows, ) (push) Blocked by required conditions
Build and Release / build (amd64, android, android-amd64) (push) Blocked by required conditions
Build and Release / build (amd64, darwin, ) (push) Blocked by required conditions
Build and Release / build (amd64, freebsd, ) (push) Blocked by required conditions
Build and Release / build (amd64, linux, ) (push) Blocked by required conditions
Build and Release / build (amd64, openbsd, ) (push) Blocked by required conditions
Build and Release / build (amd64, windows, ) (push) Blocked by required conditions
Build and Release / build (arm, 5, linux) (push) Blocked by required conditions
Build and Release / build (arm, 6, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, freebsd) (push) Blocked by required conditions
Build and Release / build (arm, 7, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, openbsd) (push) Blocked by required conditions
Build and Release / build (arm64, android) (push) Blocked by required conditions
Build and Release / build (arm64, darwin) (push) Blocked by required conditions
Build and Release / build (arm64, freebsd) (push) Blocked by required conditions
Build and Release / build (arm64, linux) (push) Blocked by required conditions
Build and Release / build (arm64, openbsd) (push) Blocked by required conditions
Build and Release / build (arm64, windows) (push) Blocked by required conditions
Build and Release / build (loong64, linux) (push) Blocked by required conditions
Build and Release / build (mips, linux) (push) Blocked by required conditions
Build and Release / build (mips64, linux) (push) Blocked by required conditions
Build and Release / build (mips64le, linux) (push) Blocked by required conditions
Build and Release / build (mipsle, linux) (push) Blocked by required conditions
Build and Release / build (ppc64, linux) (push) Blocked by required conditions
Build and Release / build (ppc64le, linux) (push) Blocked by required conditions
Build and Release / build (riscv64, linux) (push) Blocked by required conditions
Build and Release / build (s390x, linux) (push) Blocked by required conditions
Tests and Checkings / check-assets (push) Waiting to run
Tests and Checkings / check-proto (push) Waiting to run
Tests and Checkings / check-format (push) Waiting to run
Tests and Checkings / test (macos-latest) (push) Blocked by required conditions
Tests and Checkings / test (ubuntu-latest) (push) Blocked by required conditions
Tests and Checkings / test (windows-latest) (push) Blocked by required conditions
https://github.com/XTLS/Xray-core/pull/6796#issuecomment-5807809588
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package log // import "github.com/xtls/xray-core/common/log"
|
|
|
|
import (
|
|
"sync/atomic"
|
|
|
|
"github.com/xtls/xray-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)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
// Record writes a message into log stream.
|
|
func Record(msg Message) {
|
|
if h := logHandler.Load(); h != nil {
|
|
(*h).Handle(msg)
|
|
}
|
|
}
|
|
|
|
type SeverityLogger interface {
|
|
Handler
|
|
Severity() Severity
|
|
}
|
|
|
|
func GetSeverity() Severity {
|
|
if h := logHandler.Load(); h != nil {
|
|
if sh, ok := (*h).(SeverityLogger); ok {
|
|
return sh.Severity()
|
|
}
|
|
}
|
|
// log everything by default
|
|
return Severity_Debug
|
|
}
|
|
|
|
var logHandler atomic.Pointer[Handler]
|
|
|
|
// RegisterHandler registers 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")
|
|
}
|
|
logHandler.Store(&handler)
|
|
}
|