Documentation ¶
Index ¶
- Constants
- Variables
- func Fastrandn(x uint32) uint32
- func Goid() int64
- func IsTerminal(fd uintptr) bool
- func Printf(format string, v ...interface{})
- func SlogNewJSONHandler(writer io.Writer, options *slog.HandlerOptions) slog.Handler
- type AsyncWriter
- type ConsoleWriter
- type Context
- type Entry
- func (e *Entry) AnErr(key string, err error) *Entry
- func (e *Entry) Any(key string, value interface{}) *Entry
- func (e *Entry) Bool(key string, b bool) *Entry
- func (e *Entry) Bools(key string, b []bool) *Entry
- func (e *Entry) Byte(key string, val byte) *Entry
- func (e *Entry) Bytes(key string, val []byte) *Entry
- func (e *Entry) BytesOrNil(key string, val []byte) *Entry
- func (e *Entry) Caller(depth int) *Entry
- func (e *Entry) Context(ctx Context) *Entry
- func (e *Entry) Copy() Logger
- func (e *Entry) Dict(key string, ctx Context) *Entry
- func (e *Entry) Discard() *Entry
- func (e *Entry) Dur(key string, d time.Duration) *Entry
- func (e *Entry) Durs(key string, d []time.Duration) *Entry
- func (e *Entry) EmbedObject(obj ObjectMarshaler) *Entry
- func (e *Entry) Enabled() bool
- func (e *Entry) Encode(key string, val []byte, enc interface{ ... }) *Entry
- func (e *Entry) Err(err error) *Entry
- func (e *Entry) Errs(key string, errs []error) *Entry
- func (e *Entry) Fields(fields Fields) *Entry
- func (e *Entry) Float32(key string, f float32) *Entry
- func (e *Entry) Float64(key string, f float64) *Entry
- func (e *Entry) Floats32(key string, f []float32) *Entry
- func (e *Entry) Floats64(key string, f []float64) *Entry
- func (e *Entry) Func(f func(e *Entry)) *Entry
- func (e *Entry) GoStringer(key string, val fmt.GoStringer) *Entry
- func (e *Entry) Hex(key string, val []byte) *Entry
- func (e *Entry) IPAddr(key string, ip net.IP) *Entry
- func (e *Entry) IPPrefix(key string, pfx net.IPNet) *Entry
- func (e *Entry) Int(key string, i int) *Entry
- func (e *Entry) Int16(key string, i int16) *Entry
- func (e *Entry) Int32(key string, i int32) *Entry
- func (e *Entry) Int64(key string, i int64) *Entry
- func (e *Entry) Int8(key string, i int8) *Entry
- func (e *Entry) Interface(key string, i interface{}) *Entry
- func (e *Entry) Ints(key string, a []int) *Entry
- func (e *Entry) Ints16(key string, a []int16) *Entry
- func (e *Entry) Ints32(key string, a []int32) *Entry
- func (e *Entry) Ints64(key string, a []int64) *Entry
- func (e *Entry) Ints8(key string, a []int8) *Entry
- func (e *Entry) KeysAndValues(keysAndValues ...interface{}) *Entry
- func (e *Entry) MACAddr(key string, ha net.HardwareAddr) *Entry
- func (e *Entry) Map(data any) *Entry
- func (e *Entry) Msg(msg string)
- func (e *Entry) Msgf(format string, v ...interface{})
- func (e *Entry) Msgs(args ...interface{})
- func (e *Entry) NetIPAddr(key string, ip netip.Addr) *Entry
- func (e *Entry) NetIPAddrPort(key string, ipPort netip.AddrPort) *Entry
- func (e *Entry) NetIPPrefix(key string, pfx netip.Prefix) *Entry
- func (e *Entry) Object(key string, obj ObjectMarshaler) *Entry
- func (e *Entry) RawJSON(key string, b []byte) *Entry
- func (e *Entry) RawJSONStr(key string, s string) *Entry
- func (e *Entry) Stack() *Entry
- func (e *Entry) Str(key string, val string) *Entry
- func (e *Entry) StrInt(key string, val int64) *Entry
- func (e *Entry) Stringer(key string, val fmt.Stringer) *Entry
- func (e *Entry) Strs(key string, vals []string) *Entry
- func (e *Entry) Time(key string, t time.Time) *Entry
- func (e *Entry) TimeDiff(key string, t time.Time, start time.Time) *Entry
- func (e *Entry) TimeFormat(key string, timefmt string, t time.Time) *Entry
- func (e *Entry) Times(key string, a []time.Time) *Entry
- func (e *Entry) TimesFormat(key string, timefmt string, a []time.Time) *Entry
- func (e *Entry) Type(key string, v interface{}) *Entry
- func (e *Entry) Uint(key string, i uint) *Entry
- func (e *Entry) Uint16(key string, i uint16) *Entry
- func (e *Entry) Uint32(key string, i uint32) *Entry
- func (e *Entry) Uint64(key string, i uint64) *Entry
- func (e *Entry) Uint8(key string, i uint8) *Entry
- func (e *Entry) Uints(key string, a []uint) *Entry
- func (e *Entry) Uints16(key string, a []uint16) *Entry
- func (e *Entry) Uints32(key string, a []uint32) *Entry
- func (e *Entry) Uints64(key string, a []uint64) *Entry
- func (e *Entry) Uints8(key string, a []uint8) *Entry
- func (e *Entry) Value() Context
- func (e *Entry) WithContext(ctx context.Context) *Entry
- func (e *Entry) Xid(key string, id int64) *Entry
- type Fields
- type FileWriter
- type FormatterArgs
- type ID
- func NewID() ID
- func ParseBase2(id string) (ID, error)
- func ParseBase32(b []byte) (ID, error)
- func ParseBase36(id string) (ID, error)
- func ParseBase58(b []byte) (ID, error)
- func ParseBase64(id string) (ID, error)
- func ParseBytes(id []byte) (ID, error)
- func ParseInt64(id int64) ID
- func ParseIntBytes(id [8]byte) ID
- func ParseString(id string) (ID, error)
- func (f ID) Base2() string
- func (f ID) Base32() string
- func (f ID) Base36() string
- func (f ID) Base58() string
- func (f ID) Base64() string
- func (f ID) Bytes() []byte
- func (f ID) Int64() int64
- func (f ID) IntBytes() [8]byte
- func (f ID) MarshalJSON() ([]byte, error)
- func (f ID) Node() int64
- func (f ID) Step() int64
- func (f ID) String() string
- func (f ID) Time() int64
- func (f *ID) UnmarshalJSON(b []byte) error
- type IOWriteCloser
- type IOWriter
- type JSONSyntaxError
- type JournalWriter
- type Level
- type LogfmtFormatter
- type Logger
- func (l *Logger) Debug() (e *Entry)
- func (l *Logger) Err(err error) (e *Entry)
- func (l *Logger) Error() (e *Entry)
- func (l *Logger) Fatal() (e *Entry)
- func (l *Logger) Info() (e *Entry)
- func (l *Logger) Log() (e *Entry)
- func (l *Logger) Panic() (e *Entry)
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Slog() *slog.Logger
- func (l *Logger) Std(prefix string, flag int) *stdLog.Logger
- func (l *Logger) Trace() (e *Entry)
- func (l *Logger) Warn() (e *Entry)
- func (l *Logger) WithLevel(level Level) (e *Entry)
- type MultiEntryWriter
- type MultiIOWriter
- type MultiLevelWriter
- type MultiWriter
- type Node
- type ObjectMarshaler
- type SyslogWriter
- type TSVEntry
- func (e *TSVEntry) Bool(b bool) *TSVEntry
- func (e *TSVEntry) BoolString(b bool) *TSVEntry
- func (e *TSVEntry) Byte(b byte) *TSVEntry
- func (e *TSVEntry) Bytes(val []byte) *TSVEntry
- func (e *TSVEntry) Caller(depth int) *TSVEntry
- func (e *TSVEntry) Encode(key string, val []byte, enc interface{ ... }) *TSVEntry
- func (e *TSVEntry) Float32(f float32) *TSVEntry
- func (e *TSVEntry) Float64(f float64) *TSVEntry
- func (e *TSVEntry) IPAddr(ip net.IP) *TSVEntry
- func (e *TSVEntry) Int(i int) *TSVEntry
- func (e *TSVEntry) Int16(i int16) *TSVEntry
- func (e *TSVEntry) Int32(i int32) *TSVEntry
- func (e *TSVEntry) Int64(i int64) *TSVEntry
- func (e *TSVEntry) Int8(i int8) *TSVEntry
- func (e *TSVEntry) Msg()
- func (e *TSVEntry) NetIPAddr(ip netip.Addr) *TSVEntry
- func (e *TSVEntry) NetIPAddrPort(ipPort netip.AddrPort) *TSVEntry
- func (e *TSVEntry) NetIPPrefix(pfx netip.Prefix) *TSVEntry
- func (e *TSVEntry) Str(val string) *TSVEntry
- func (e *TSVEntry) Timestamp() *TSVEntry
- func (e *TSVEntry) TimestampMS() *TSVEntry
- func (e *TSVEntry) Uint(i uint) *TSVEntry
- func (e *TSVEntry) Uint16(i uint16) *TSVEntry
- func (e *TSVEntry) Uint32(i uint32) *TSVEntry
- func (e *TSVEntry) Uint64(i uint64) *TSVEntry
- func (e *TSVEntry) Uint8(i uint8) *TSVEntry
- type TSVLogger
- type Writer
- type WriterFunc
Constants ¶
const TimeFormatUnix = "\x01"
TimeFormatUnix defines a time format that makes time fields to be serialized as Unix timestamp integers.
const TimeFormatUnixMs = "\x02"
TimeFormatUnixMs defines a time format that makes time fields to be serialized as Unix timestamp integers in milliseconds.
const TimeFormatUnixWithMs = "\x03"
TimeFormatUnixWithMs defines a time format that makes time fields to be serialized as Unix timestamp timestamp floats.
Variables ¶
var ( // Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds // You may customize this to set a different epoch for your application. Epoch int64 = 1288834974657 // NodeBits holds the number of bits to use for Node // Remember, you have a total 22 bits to share between Node/Step NodeBits uint8 = 10 // StepBits holds the number of bits to use for Step // Remember, you have a total 22 bits to share between Node/Step StepBits uint8 = 12 )
var DefaultLogger = Logger{ Level: DebugLevel, LogNode: false, EnableTracing: true, TraceIDField: "trace_id", Caller: 0, TimeField: "", TimeFormat: "", Writer: IOWriter{os.Stderr}, }
DefaultLogger is the global logger.
var ErrInvalidBase32 = errors.New("invalid base32")
ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte
var ErrInvalidBase58 = errors.New("invalid base58")
ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte
Functions ¶
func Goid ¶
func Goid() int64
Goid returns the current goroutine id. It exactly matches goroutine id of the stack trace.
func IsTerminal ¶
IsTerminal returns whether the given file descriptor is a terminal.
func Printf ¶
func Printf(format string, v ...interface{})
Printf sends a log entry without extra field. Arguments are handled in the manner of fmt.Printf.
func SlogNewJSONHandler ¶
Types ¶
type AsyncWriter ¶
type AsyncWriter struct { // ChannelSize is the size of the data channel, the default size is 1. ChannelSize uint // Writer specifies the writer of output. Writer Writer // contains filtered or unexported fields }
AsyncWriter is an Writer that writes asynchronously.
func (*AsyncWriter) Close ¶
func (w *AsyncWriter) Close() (err error)
Close implements io.Closer, and closes the underlying Writer.
func (*AsyncWriter) WriteEntry ¶
func (w *AsyncWriter) WriteEntry(e *Entry) (int, error)
WriteEntry implements Writer.
type ConsoleWriter ¶
type ConsoleWriter struct { // ColorOutput determines if used colorized output. ColorOutput bool // QuoteString determines if quoting string values. QuoteString bool // EndWithMessage determines if output message in the end. EndWithMessage bool // Formatter specifies an optional text formatter for creating a customized output, // If it is set, ColorOutput, QuoteString and EndWithMessage will be ignore. Formatter func(w io.Writer, args *FormatterArgs) (n int, err error) // Writer is the output destination. using os.Stderr if empty. Writer io.Writer }
ConsoleWriter parses the JSON input and writes it in a colorized, human-friendly format to Writer. IMPORTANT: Don't use ConsoleWriter on critical path of a high concurrency and low latency application.
Default output format:
{Time} {Level} {Goid} {Caller} > {Message} {Key}={Value} {Key}={Value}
Note: The performance of ConsoleWriter is not good enough, because it will parses JSON input into structured records, then output in a specific order. Roughly 2x faster than logrus.TextFormatter, 0.8x fast as zap.ConsoleEncoder, and 5x faster than zerolog.ConsoleWriter.
func (*ConsoleWriter) Close ¶
func (w *ConsoleWriter) Close() (err error)
Close implements io.Closer, will closes the underlying Writer if not empty.
func (*ConsoleWriter) WriteEntry ¶
func (w *ConsoleWriter) WriteEntry(e *Entry) (int, error)
WriteEntry implements Writer.
type Entry ¶
type Entry struct { Level Level // contains filtered or unexported fields }
Entry represents a log entry. It is instanced by one of the level method of Logger and finalized by the Msg or Msgf method.
func (*Entry) BytesOrNil ¶
BytesOrNil adds the field key with val as a string or nil to the entry.
func (*Entry) Caller ¶
Caller adds the file:line of the "caller" key. If depth is negative, adds the full /path/to/file:line of the "caller" key.
func (*Entry) EmbedObject ¶
func (e *Entry) EmbedObject(obj ObjectMarshaler) *Entry
EmbedObject marshals and Embeds an object that implement the ObjectMarshaler interface.
func (*Entry) Encode ¶
func (e *Entry) Encode(key string, val []byte, enc interface { AppendEncode(dst, src []byte) []byte }) *Entry
Encode encodes bytes using enc.AppendEncode to the entry.
func (*Entry) Errs ¶
Errs adds the field key with errs as an array of serialized errors to the entry.
func (*Entry) GoStringer ¶
func (e *Entry) GoStringer(key string, val fmt.GoStringer) *Entry
GoStringer adds the field key with val.GoStringer() to the entry.
func (*Entry) KeysAndValues ¶
KeysAndValues sends keysAndValues to Entry
func (*Entry) MACAddr ¶
func (e *Entry) MACAddr(key string, ha net.HardwareAddr) *Entry
MACAddr adds MAC address to the entry.
func (*Entry) Msgf ¶
Msgf sends the entry with formatted msg added as the message field if not empty.
func (*Entry) Msgs ¶
func (e *Entry) Msgs(args ...interface{})
Msgs sends the entry with msgs added as the message field if not empty.
func (*Entry) NetIPAddrPort ¶
NetIPAddrPort adds IPv4 or IPv6 with Port Address to the entry.
func (*Entry) NetIPPrefix ¶
NetIPPrefix adds IPv4 or IPv6 Prefix (address and mask) to the entry.
func (*Entry) Object ¶
func (e *Entry) Object(key string, obj ObjectMarshaler) *Entry
Object marshals an object that implement the ObjectMarshaler interface.
func (*Entry) RawJSONStr ¶
RawJSONStr adds already encoded JSON String to the log line under key.
func (*Entry) TimeDiff ¶
TimeDiff adds the field key with positive duration between time t and start. If time t is not greater than start, duration will be 0. Duration format follows the same principle as Dur().
func (*Entry) TimeFormat ¶
TimeFormat append t formatted as string using timefmt.
func (*Entry) TimesFormat ¶
TimesFormat append a formatted as string array using timefmt.
func (*Entry) WithContext ¶
WithContext use context
type FileWriter ¶
type FileWriter struct { // Filename is the file to write logs to. Backup log files will be retained // in the same directory. Filename string // MaxSize is the maximum size in bytes of the log file before it gets rotated. MaxSize int64 // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files MaxBackups int // FileMode represents the file's mode and permission bits. The default // mode is 0644 FileMode os.FileMode // TimeFormat specifies the time format of filename, uses `2006-01-02T15-04-05` as default format. // If set with `TimeFormatUnix`, `TimeFormatUnixMs`, times are formated as UNIX timestamp. TimeFormat string // LocalTime determines if the time used for formatting the timestamps in // log files is the computer's local time. The default is to use UTC time. LocalTime bool // HostName determines if the hostname used for formatting in log files. HostName bool // ProcessID determines if the pid used for formatting in log files. ProcessID bool // EnsureFolder ensures the file directory creation before writing. EnsureFolder bool // Header specifies an optional header function of log file after rotation, Header func(fileinfo os.FileInfo) []byte // Cleaner specifies an optional cleanup function of log backups after rotation, // if not set, the default behavior is to delete more than MaxBackups log files. Cleaner func(filename string, maxBackups int, matches []os.FileInfo) // contains filtered or unexported fields }
FileWriter is an Writer that writes to the specified filename.
Backups use the log file name given to FileWriter, in the form `name.timestamp.ext` where name is the filename without the extension, timestamp is the time at which the log was rotated formatted with the time.Time format of `2006-01-02T15-04-05` and the extension is the original extension. For example, if your FileWriter.Filename is `/var/log/foo/server.log`, a backup created at 6:30pm on Nov 11 2016 would use the filename `/var/log/foo/server.2016-11-04T18-30-00.log`
Cleaning Up Old Log Files ¶
Whenever a new logfile gets created, old log files may be deleted. The most recent files according to filesystem modified time will be retained, up to a number equal to MaxBackups (or all of them if MaxBackups is 0). Note that the time encoded in the timestamp is the rotation time, which may differ from the last time that file was written to .
func (*FileWriter) Close ¶
func (w *FileWriter) Close() (err error)
Close implements io.Closer, and closes the current logfile.
func (*FileWriter) Rotate ¶
func (w *FileWriter) Rotate() (err error)
Rotate causes Logger to close the existing log file and immediately create a new one. This is a helper function for applications that want to initiate rotations outside of the normal rotation rules, such as in response to SIGHUP. After rotating, this initiates compression and removal of old log files according to the configuration.
func (*FileWriter) Write ¶
func (w *FileWriter) Write(p []byte) (n int, err error)
Write implements io.Writer. If a write would cause the log file to be larger than MaxSize, the file is closed, rotate to include a timestamp of the current time, and update symlink with log name file to the new file.
func (*FileWriter) WriteEntry ¶
func (w *FileWriter) WriteEntry(e *Entry) (n int, err error)
WriteEntry implements Writer. If a write would cause the log file to be larger than MaxSize, the file is closed, rotate to include a timestamp of the current time, and update symlink with log name file to the new file.
type FormatterArgs ¶
type FormatterArgs struct { Time string // "2019-07-10T05:35:54.277Z" Level string // "info" Caller string // "prog.go:42" Goid string // "123" Stack string // "<stack string>" Message string // "a structure message" KeyValues []struct { Key string // "foo" Value string // "bar" ValueType byte // 's' } }
FormatterArgs is a parsed sturct from json input
func (*FormatterArgs) Get ¶
func (args *FormatterArgs) Get(key string) (value string)
Get gets the value associated with the given key.
type ID ¶
type ID int64
An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.
func ParseBase2 ¶
ParseBase2 converts a Base2 string into a snowflake ID
func ParseBase32 ¶
ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so becareful when doing Any interoperation.
func ParseBase36 ¶
ParseBase36 converts a Base36 string into a snowflake ID
func ParseBase58 ¶
ParseBase58 parses a base58 []byte into a snowflake ID
func ParseBase64 ¶
ParseBase64 converts a base64 string into a snowflake ID
func ParseBytes ¶
ParseBytes converts a byte slice into a snowflake ID
func ParseIntBytes ¶
ParseIntBytes converts an array of bytes encoded as big endian integer as a snowflake ID
func ParseString ¶
ParseString converts a string into a snowflake ID
func (ID) Base32 ¶
Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing Any interoperation.
func (ID) IntBytes ¶
IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.
func (ID) MarshalJSON ¶
MarshalJSON returns a json byte array string of the snowflake ID.
func (ID) Node ¶
Node returns an int64 of the snowflake ID node number DEPRECATED: the below function will be removed in a future release.
func (ID) Step ¶
Step returns an int64 of the snowflake step (or sequence) number DEPRECATED: the below function will be removed in a future release.
func (ID) Time ¶
Time returns an int64 unix timestamp in milliseconds of the snowflake ID time DEPRECATED: the below function will be removed in a future release.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON converts a json byte array of a snowflake ID into an ID type .
type IOWriteCloser ¶
type IOWriteCloser struct {
io.WriteCloser
}
IOWriteCloser wraps an io.IOWriteCloser to Writer.
func (IOWriteCloser) WriteEntry ¶
func (w IOWriteCloser) WriteEntry(e *Entry) (n int, err error)
WriteEntry implements Writer.
type JSONSyntaxError ¶
type JSONSyntaxError struct {
// contains filtered or unexported fields
}
A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.
func (JSONSyntaxError) Error ¶
func (j JSONSyntaxError) Error() string
type JournalWriter ¶
type JournalWriter struct { // JournalSocket specifies socket name, using `/run/systemd/journal/socket` if empty. JournalSocket string // contains filtered or unexported fields }
JournalWriter is an Writer that writes logs to journald.
func (*JournalWriter) Close ¶
func (w *JournalWriter) Close() (err error)
Close implements io.Closer.
func (*JournalWriter) WriteEntry ¶
func (w *JournalWriter) WriteEntry(e *Entry) (n int, err error)
WriteEntry implements Writer.
type Level ¶
type Level uint32
Level defines log levels.
const ( // TraceLevel defines trace log level. TraceLevel Level = 1 // DebugLevel defines debug log level. DebugLevel Level = 2 // InfoLevel defines info log level. InfoLevel Level = 3 // WarnLevel defines warn log level. WarnLevel Level = 4 // ErrorLevel defines error log level. ErrorLevel Level = 5 // FatalLevel defines fatal log level. FatalLevel Level = 6 // PanicLevel defines panic log level. PanicLevel Level = 7 )
func ParseLevel ¶
ParseLevel converts a level string into a log Level value.
type LogfmtFormatter ¶
type LogfmtFormatter struct {
TimeField string
}
func (LogfmtFormatter) Formatter ¶
func (f LogfmtFormatter) Formatter(out io.Writer, args *FormatterArgs) (n int, err error)
type Logger ¶
type Logger struct { // Level defines log levels. Level Level LogNode bool EnableTracing bool TraceIDField string // Caller determines if adds the file:line of the "caller" key. // If Caller is negative, adds the full /path/to/file:line of the "caller" key. Caller int // TimeField defines the time field name in output. It uses "time" in if empty. TimeField string // TimeFormat specifies the time format in output. It uses time.RFC3339 with milliseconds if empty. // If set with `TimeFormatUnix`, `TimeFormatUnixMs`, times are formated as UNIX timestamp. TimeFormat string // TimeLocation specifices that the location which TimeFormat used. It uses time.Local if empty. TimeLocation *time.Location // Context specifies an optional context of logger. Context Context // Writer specifies the writer of output. It uses a wrapped os.Stderr Writer in if empty. Writer Writer }
A Logger represents an active logging object that generates lines of JSON output to an io.Writer.
func (*Logger) Err ¶
Err starts a new message with error level with err as a field if not nil or with info level if err is nil.
func (*Logger) Printf ¶
Printf sends a log entry without extra field. Arguments are handled in the manner of fmt.Printf.
type MultiEntryWriter ¶
type MultiEntryWriter []Writer
MultiEntryWriter is an array Writer that log to different writers
func (*MultiEntryWriter) Close ¶
func (w *MultiEntryWriter) Close() (err error)
Close implements io.Closer, and closes the underlying MultiEntryWriter.
func (*MultiEntryWriter) WriteEntry ¶
func (w *MultiEntryWriter) WriteEntry(e *Entry) (n int, err error)
WriteEntry implements entryWriter.
type MultiIOWriter ¶
MultiIOWriter is an array io.Writer that log to different writers
func (*MultiIOWriter) Close ¶
func (w *MultiIOWriter) Close() (err error)
Close implements io.Closer, and closes the underlying MultiIOWriter.
func (*MultiIOWriter) WriteEntry ¶
func (w *MultiIOWriter) WriteEntry(e *Entry) (n int, err error)
WriteEntry implements entryWriter.
type MultiLevelWriter ¶
type MultiLevelWriter struct { // InfoWriter specifies all the level logs writes to InfoWriter Writer // WarnWriter specifies the level greater than or equal to WarnLevel writes to WarnWriter Writer // WarnWriter specifies the level greater than or equal to ErrorLevel writes to ErrorWriter Writer // ConsoleWriter specifies the console writer ConsoleWriter Writer // ConsoleLevel specifies the level greater than or equal to it also writes to ConsoleLevel Level }
MultiLevelWriter is an Writer that log to different writers by different levels
func (*MultiLevelWriter) Close ¶
func (w *MultiLevelWriter) Close() (err error)
Close implements io.Closer, and closes the underlying LeveledWriter.
func (*MultiLevelWriter) WriteEntry ¶
func (w *MultiLevelWriter) WriteEntry(e *Entry) (n int, err error)
WriteEntry implements entryWriter.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
A Node struct holds the basic information needed for a snowflake generator node
type ObjectMarshaler ¶
type ObjectMarshaler interface {
MarshalObject(e *Entry)
}
ObjectMarshaler provides a strongly-typed and encoding-agnostic interface to be implemented by types used with Entry's Object methods.
type SyslogWriter ¶
type SyslogWriter struct { // Network specifies network of the syslog server Network string // Address specifies address of the syslog server Address string // Hostname specifies hostname of the syslog message Hostname string // Tag specifies tag of the syslog message Tag string // Marker specifies prefix of the syslog message, e.g. `@cee:` Marker string // Dial specifies the dial function for creating TCP/TLS connections. Dial func(network, addr string) (net.Conn, error) // contains filtered or unexported fields }
SyslogWriter is an Writer that writes logs to a syslog server..
func (*SyslogWriter) Close ¶
func (w *SyslogWriter) Close() (err error)
Close closes a connection to the syslog server.
func (*SyslogWriter) WriteEntry ¶
func (w *SyslogWriter) WriteEntry(e *Entry) (n int, err error)
WriteEntry implements Writer, sends logs with priority to the syslog server.
type TSVEntry ¶
type TSVEntry struct {
// contains filtered or unexported fields
}
TSVEntry represents a tsv log entry. It is instanced by one of TSVLogger and finalized by the Msg method.
func (*TSVEntry) Bool ¶
Bool append the b as a bool to the entry, the value of output bool is 0 or 1.
func (*TSVEntry) BoolString ¶
BoolString append the b as a bool to the entry, the value of output bool is false or true.
func (*TSVEntry) Encode ¶
func (e *TSVEntry) Encode(key string, val []byte, enc interface { AppendEncode(dst, src []byte) []byte }) *TSVEntry
Encode encodes bytes using enc.AppendEncode to the entry.
func (*TSVEntry) NetIPAddrPort ¶
NetIPAddrPort adds IPv4 or IPv6 with Port Address to the entry.
func (*TSVEntry) NetIPPrefix ¶
NetIPPrefix adds IPv4 or IPv6 Prefix (address and mask) to the entry.
func (*TSVEntry) TimestampMS ¶
TimestampMS adds the current time with milliseconds as UNIX timestamp
type TSVLogger ¶
TSVLogger represents an active logging object that generates lines of TSV output to an io.Writer.
type WriterFunc ¶
The WriterFunc type is an adapter to allow the use of ordinary functions as log writers. If f is a function with the appropriate signature, WriterFunc(f) is a Writer that calls f.
func (WriterFunc) WriteEntry ¶
func (f WriterFunc) WriteEntry(e *Entry) (int, error)
WriteEntry calls f(e).