Logger v0.1.0
Logger
pub struct Logger {
// private fields
}
Writes records at or above a level to a stream, each as one write. Not copied.
A logging call never fails: the first failure to write is kept for Failure to report, and the records after it
are still attempted. A logger is used by one thread at a time; the process-wide functions such as Info are the
ones to share between threads.
Associated functions
New
pub func New(
allocator: Allocator,
sink: Writer,
format: LogFormat
) -> Logger
A logger writing records in format to sink, at level Info and above, with times.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | what each record is built in before it is written |
sink | Writer | where the records go |
format | LogFormat | how they are written |
Returns: the logger
Methods
SetLevel
pub func SetLevel(self: &var Logger, level: Level)
Writes records at level and above from now on.
| Name | Type | Description |
|---|---|---|
level | Level | the least severe level written |
MinimumLevel
pub func MinimumLevel(self: &Logger) -> Level
The least severe level written.
Returns: the level
Enabled
pub func Enabled(self: &Logger, level: Level) -> bool
Whether a record at level would be written, by this logger's level and the build's CompiledLevel. Worth
asking before working out fields that cost something to compute.
| Name | Type | Description |
|---|---|---|
level | Level | the level to ask about |
Returns: whether it would be written
SetTimestamps
pub func SetTimestamps(self: &var Logger, enabled: bool)
Whether records start with the time. Leaving it out suits a destination that adds its own, such as a service manager's journal.
| Name | Type | Description |
|---|---|---|
enabled | bool | whether to write the time |
SetContext
pub func SetContext(self: &var Logger, fields: Field[..])
Fields written with every record, before the record's own, such as a request's identifier.
| Name | Type | Description |
|---|---|---|
fields | Field[..] | the fields, borrowed until they are replaced |
Failure
pub func Failure(self: &Logger) -> IoError?
The first failure to write a record, or none when every record was written.
Returns: the failure
Log
pub func Log(
self: &var Logger,
level: Level,
message: char8[..],
fields: Field[..]
)
Writes a record at level with message and fields, if the level is enabled.
| Name | Type | Description |
|---|---|---|
level | Level | how severe it is |
message | char8[..] | what happened |
fields | Field[..] | the values that go with it |
Flush
pub func Flush(self: &var Logger)
Asks the stream to deliver what it holds.
Trace
pub func Trace(
self: &var Logger,
message: char8[..],
fields: Field[..]
)
pub func Trace(self: &var Logger, message: char8[..])
Writes a Trace record with no fields.
| Overload | Summary |
|---|---|
pub func Trace(self: &var Logger, message: char8[..], fields: Field[..]) | Writes a Trace record. |
pub func Trace(self: &var Logger, message: char8[..]) | Writes a Trace record with no fields. |
| Name | Type | Description |
|---|---|---|
message | char8[..] | what happened |
fields | Field[..] | the values that go with it |
Debug
pub func Debug(
self: &var Logger,
message: char8[..],
fields: Field[..]
)
pub func Debug(self: &var Logger, message: char8[..])
Writes a Debug record with no fields.
| Overload | Summary |
|---|---|
pub func Debug(self: &var Logger, message: char8[..], fields: Field[..]) | Writes a Debug record. |
pub func Debug(self: &var Logger, message: char8[..]) | Writes a Debug record with no fields. |
| Name | Type | Description |
|---|---|---|
message | char8[..] | what happened |
fields | Field[..] | the values that go with it |
Info
pub func Info(
self: &var Logger,
message: char8[..],
fields: Field[..]
)
pub func Info(self: &var Logger, message: char8[..])
Writes an Info record with no fields.
| Overload | Summary |
|---|---|
pub func Info(self: &var Logger, message: char8[..], fields: Field[..]) | Writes an Info record. |
pub func Info(self: &var Logger, message: char8[..]) | Writes an Info record with no fields. |
| Name | Type | Description |
|---|---|---|
message | char8[..] | what happened |
fields | Field[..] | the values that go with it |
Warn
pub func Warn(
self: &var Logger,
message: char8[..],
fields: Field[..]
)
pub func Warn(self: &var Logger, message: char8[..])
Writes a Warn record with no fields.
| Overload | Summary |
|---|---|
pub func Warn(self: &var Logger, message: char8[..], fields: Field[..]) | Writes a Warn record. |
pub func Warn(self: &var Logger, message: char8[..]) | Writes a Warn record with no fields. |
| Name | Type | Description |
|---|---|---|
message | char8[..] | what happened |
fields | Field[..] | the values that go with it |
Error
pub func Error(
self: &var Logger,
message: char8[..],
fields: Field[..]
)
pub func Error(self: &var Logger, message: char8[..])
Writes an Error record with no fields.
| Overload | Summary |
|---|---|
pub func Error(self: &var Logger, message: char8[..], fields: Field[..]) | Writes an Error record. |
pub func Error(self: &var Logger, message: char8[..]) | Writes an Error record with no fields. |
| Name | Type | Description |
|---|---|---|
message | char8[..] | what happened |
fields | Field[..] | the values that go with it |