Documentation
¶
Index ¶
- Constants
- Variables
- type FastLogger
- func (logger *FastLogger) Error(args ...interface{})
- func (logger *FastLogger) ErrorPrepare(record *Record)
- func (logger *FastLogger) Fatal(args ...interface{})
- func (logger *FastLogger) FatalPrepare(record *Record)
- func (logger *FastLogger) Flush()
- func (logger *FastLogger) FormatError(f string, args ...interface{})
- func (logger *FastLogger) FormatFatal(f string, args ...interface{})
- func (logger *FastLogger) FormatInfo(f string, args ...interface{})
- func (logger *FastLogger) FormatSuccess(f string, args ...interface{})
- func (logger *FastLogger) FormatWarning(f string, args ...interface{})
- func (logger *FastLogger) Info(args ...interface{})
- func (logger *FastLogger) InfoPrepare(record *Record)
- func (logger *FastLogger) Raw(data []byte)
- func (logger *FastLogger) Record(record *Record)
- func (logger *FastLogger) Stop()
- func (logger *FastLogger) StopWithoutFlush()
- func (logger *FastLogger) Success(args ...interface{})
- func (logger *FastLogger) SuccessPrepare(record *Record)
- func (logger *FastLogger) Warning(args ...interface{})
- func (logger *FastLogger) WarningPrepare(record *Record)
- type FastLoggerConfig
- type Record
- func (r *Record) AppendArgs(args ...interface{}) *Record
- func (r *Record) AppendFormat(format string, args ...interface{}) *Record
- func (r *Record) Build() *Record
- func (r *Record) NewLine(flag bool) *Record
- func (r *Record) NoDate() *Record
- func (r *Record) Prefix(prefix string) *Record
- func (r *Record) Prepare() *Record
- func (r *Record) Reset()
- func (r *Record) ShowDate() *Record
- type StandardLogger
- func (logger *StandardLogger) Close()
- func (logger *StandardLogger) Error(args ...interface{})
- func (logger *StandardLogger) ErrorPrepare(record *Record)
- func (logger *StandardLogger) Fatal(args ...interface{})
- func (logger *StandardLogger) FatalPrepare(record *Record)
- func (logger *StandardLogger) FormatError(f string, args ...interface{})
- func (logger *StandardLogger) FormatFatal(f string, args ...interface{})
- func (logger *StandardLogger) FormatInfo(f string, args ...interface{})
- func (logger *StandardLogger) FormatSuccess(f string, args ...interface{})
- func (logger *StandardLogger) FormatWarning(f string, args ...interface{})
- func (logger *StandardLogger) Info(args ...interface{})
- func (logger *StandardLogger) InfoPrepare(record *Record)
- func (logger *StandardLogger) Raw(record []byte)
- func (logger *StandardLogger) RawWithWriter(record []byte, writer io.Writer)
- func (logger *StandardLogger) Record(record *Record)
- func (logger *StandardLogger) RecordWithWriter(record Record, writer io.Writer)
- func (logger *StandardLogger) Success(args ...interface{})
- func (logger *StandardLogger) SuccessPrepare(record *Record)
- func (logger *StandardLogger) Warning(args ...interface{})
- func (logger *StandardLogger) WarningPrepare(record *Record)
- type StandardLoggerConfig
Constants ¶
const CountOfStorages = 256
CountOfStorages is the number of storages. It must be power of 2.
const Lob = CountOfStorages - 1
Lob is low-order bits.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type FastLogger ¶
type FastLogger struct {
// contains filtered or unexported fields
}
FastLogger is a logger that writes to the standard logger with buffers. FastLogger is thread-safe and faster than StandardLogger by many orders. FastLogger will not log buffers if the application crashes before the recording interval has passed! If you don't use panics outside FastLogger, FastLogger will only not record if the machine is turned off. Use FastLogger.Fatal() or FastLogger.FormatFatal() instead of panic, or use FastLogger.Flush() before shutting down the application.
Example:
cfg := &FastLoggerConfig{ StandardLoggerConfig: StandardLoggerConfig{ IsWritingToTheConsole: true, ErrorWriter: errorFile, WarningWriter: warningFile, InfoWriter: infoFile, SuccessWriter: successFile, FatalWriter: fatalFile, RecordWriter: recordFile, RawWriter: rawFile, }, FlushInterval: 1 * time.Second, FatalFunc: func(reason any) { panic(fmt.Sprintf("logger could not write to the file reason: %v", reason)) }, }
logger := NewFastLogger(cfg)
func NewFastLogger ¶
func NewFastLogger(cfg *FastLoggerConfig) *FastLogger
NewFastLogger creates a new FastLogger.
func (*FastLogger) Error ¶
func (logger *FastLogger) Error(args ...interface{})
Error logs a message to the logger.stdLogger.errorWriter.
func (*FastLogger) ErrorPrepare ¶
func (logger *FastLogger) ErrorPrepare(record *Record)
ErrorPrepare logs a prepared record to the logger.errorWriter. Will not reset the record.
func (*FastLogger) Fatal ¶
func (logger *FastLogger) Fatal(args ...interface{})
Fatal logs a message to the logger.stdLogger.fatalWriter.
func (*FastLogger) FatalPrepare ¶
func (logger *FastLogger) FatalPrepare(record *Record)
FatalPrepare logs a prepared record to the logger.fatalWriter. Will not reset the record.
func (*FastLogger) FormatError ¶
func (logger *FastLogger) FormatError(f string, args ...interface{})
FormatError logs a message with format to the logger.stdLogger.errorWriter.
func (*FastLogger) FormatFatal ¶
func (logger *FastLogger) FormatFatal(f string, args ...interface{})
FormatFatal logs a message with format to the logger.stdLogger.fatalWriter.
func (*FastLogger) FormatInfo ¶
func (logger *FastLogger) FormatInfo(f string, args ...interface{})
FormatInfo logs a message with format to the logger.stdLogger.infoWriter.
func (*FastLogger) FormatSuccess ¶
func (logger *FastLogger) FormatSuccess(f string, args ...interface{})
FormatSuccess logs a message with format to the logger.stdLogger.successWriter.
func (*FastLogger) FormatWarning ¶
func (logger *FastLogger) FormatWarning(f string, args ...interface{})
FormatWarning logs a message with format to the logger.stdLogger.warningWriter.
func (*FastLogger) Info ¶
func (logger *FastLogger) Info(args ...interface{})
func (*FastLogger) InfoPrepare ¶
func (logger *FastLogger) InfoPrepare(record *Record)
InfoPrepare logs a prepared record to the logger.infoWriter. Will not reset the record.
func (*FastLogger) Raw ¶
func (logger *FastLogger) Raw(data []byte)
Raw logs a raw log to the logger.stdLogger.rawWriter.
func (*FastLogger) Record ¶
func (logger *FastLogger) Record(record *Record)
Record logs a record to the logger.stdLogger.recordWriter.
func (*FastLogger) StopWithoutFlush ¶
func (logger *FastLogger) StopWithoutFlush()
StopWithoutFlush stops the logger without flushing. WILL CLEAR NOT FLUSHED LOGS!
func (*FastLogger) Success ¶
func (logger *FastLogger) Success(args ...interface{})
Success logs a message to the logger.stdLogger.successWriter.
func (*FastLogger) SuccessPrepare ¶
func (logger *FastLogger) SuccessPrepare(record *Record)
SuccessPrepare logs a prepared record to the logger.successWriter. Will not reset the record.
func (*FastLogger) Warning ¶
func (logger *FastLogger) Warning(args ...interface{})
Warning logs a message to the logger.stdLogger.warningWriter.
func (*FastLogger) WarningPrepare ¶
func (logger *FastLogger) WarningPrepare(record *Record)
WarningPrepare logs a prepared record to the logger.warningWriter. Will not reset the record.
type FastLoggerConfig ¶
type FastLoggerConfig struct { StandardLoggerConfig // FlushInterval is the interval between flushes to the writers. FlushInterval time.Duration // FatalFunc is the function to call when a fatal error occurs in the logger. FatalFunc func(reason any) }
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func NewBuilder() *Record
func (*Record) AppendArgs ¶
func (*Record) AppendFormat ¶
type StandardLogger ¶
type StandardLogger struct {
// contains filtered or unexported fields
}
func NewStandardLogger ¶
func NewStandardLogger(cfg *StandardLoggerConfig) *StandardLogger
NewStandardLogger creates a new StandardLogger.
func (*StandardLogger) Close ¶ added in v1.3.0
func (logger *StandardLogger) Close()
Close closes the logger. The logger can no longer be used.
func (*StandardLogger) Error ¶
func (logger *StandardLogger) Error(args ...interface{})
Error logs a message to the logger.errorWriter.
func (*StandardLogger) ErrorPrepare ¶
func (logger *StandardLogger) ErrorPrepare(record *Record)
ErrorPrepare logs a prepared record to the logger.errorWriter. Will not reset the record.
func (*StandardLogger) Fatal ¶
func (logger *StandardLogger) Fatal(args ...interface{})
Fatal logs a message to the logger.fatalWriter. It will exit the program.
func (*StandardLogger) FatalPrepare ¶
func (logger *StandardLogger) FatalPrepare(record *Record)
FatalPrepare logs a prepared record to the logger.fatalWriter. Will not reset the record.
func (*StandardLogger) FormatError ¶
func (logger *StandardLogger) FormatError(f string, args ...interface{})
FormatError logs a message with format to the logger.errorWriter.
func (*StandardLogger) FormatFatal ¶
func (logger *StandardLogger) FormatFatal(f string, args ...interface{})
FormatFatal logs a message with format to the logger.fatalWriter. It will exit the program.
func (*StandardLogger) FormatInfo ¶
func (logger *StandardLogger) FormatInfo(f string, args ...interface{})
FormatInfo logs a message with format to the logger.infoWriter.
func (*StandardLogger) FormatSuccess ¶
func (logger *StandardLogger) FormatSuccess(f string, args ...interface{})
FormatSuccess logs a message with format to the logger.successWriter.
func (*StandardLogger) FormatWarning ¶
func (logger *StandardLogger) FormatWarning(f string, args ...interface{})
FormatWarning logs a message with format to the logger.warningWriter.
func (*StandardLogger) Info ¶
func (logger *StandardLogger) Info(args ...interface{})
Info logs a message to the logger.infoWriter.
func (*StandardLogger) InfoPrepare ¶
func (logger *StandardLogger) InfoPrepare(record *Record)
InfoPrepare logs a prepared record to the logger.infoWriter. Will not reset the record.
func (*StandardLogger) Raw ¶
func (logger *StandardLogger) Raw(record []byte)
Raw logs a raw log to the logger.rawWriter.
func (*StandardLogger) RawWithWriter ¶
func (logger *StandardLogger) RawWithWriter(record []byte, writer io.Writer)
RawWithWriter logs a raw log to the writer.
func (*StandardLogger) Record ¶
func (logger *StandardLogger) Record(record *Record)
Record logs a record to the logger.recordWriter. You can create a record with Builder(). Will reset the record.
func (*StandardLogger) RecordWithWriter ¶
func (logger *StandardLogger) RecordWithWriter(record Record, writer io.Writer)
RecordWithWriter logs a record to the writer. You can create a record with Builder().
func (*StandardLogger) Success ¶
func (logger *StandardLogger) Success(args ...interface{})
Success logs a message to the logger.successWriter.
func (*StandardLogger) SuccessPrepare ¶
func (logger *StandardLogger) SuccessPrepare(record *Record)
SuccessPrepare logs a prepared record to the logger.successWriter. Will not reset the record.
func (*StandardLogger) Warning ¶
func (logger *StandardLogger) Warning(args ...interface{})
Warning logs a message to the logger.warningWriter.
func (*StandardLogger) WarningPrepare ¶
func (logger *StandardLogger) WarningPrepare(record *Record)
WarningPrepare logs a prepared record to the logger.warningWriter. Will not reset the record.
type StandardLoggerConfig ¶
type StandardLoggerConfig struct { MaxBufferSize int // IsWritingToTheConsole indicates whether the logger should write to the console. IsWritingToTheConsole bool // ErrorWriter is the writer to which errors will be written. ErrorWriter io.Writer // WarningWriter is the writer to which warnings will be written. WarningWriter io.Writer // InfoWriter is the writer to which information will be written. InfoWriter io.Writer // SuccessWriter is the writer to which successes will be written. SuccessWriter io.Writer // FatalWriter is the writer to which errors will be written. FatalWriter io.Writer // RecordWriter is the writer to which records will be written. RecordWriter io.Writer // RawWriter is the writer to which raw logs will be written. RawWriter io.Writer ShowDate bool }