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.
Constructors
Logger
pub func Logger(
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(&var self, 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) -> Level
The least severe level written.
Returns: the level
Enabled
pub func Enabled(&self, 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(&var self, 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(&var self, 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) -> IoError?
The first failure to write a record, or none when every record was written.
Returns: the failure
Log
pub func Log(
&var self,
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(&var self)
Asks the stream to deliver what it holds.
Trace
pub func Trace(
&var self,
message: char8[..],
fields: Field[..]
)
pub func Trace(&var self, message: char8[..])
Writes a Trace record with no fields.
| Overload | Summary |
|---|---|
pub func Trace(&var self, message: char8[..], fields: Field[..]) | Writes a Trace record. |
pub func Trace(&var self, 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(
&var self,
message: char8[..],
fields: Field[..]
)
pub func Debug(&var self, message: char8[..])
Writes a Debug record with no fields.
| Overload | Summary |
|---|---|
pub func Debug(&var self, message: char8[..], fields: Field[..]) | Writes a Debug record. |
pub func Debug(&var self, 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(
&var self,
message: char8[..],
fields: Field[..]
)
pub func Info(&var self, message: char8[..])
Writes an Info record with no fields.
| Overload | Summary |
|---|---|
pub func Info(&var self, message: char8[..], fields: Field[..]) | Writes an Info record. |
pub func Info(&var self, 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(
&var self,
message: char8[..],
fields: Field[..]
)
pub func Warn(&var self, message: char8[..])
Writes a Warn record with no fields.
| Overload | Summary |
|---|---|
pub func Warn(&var self, message: char8[..], fields: Field[..]) | Writes a Warn record. |
pub func Warn(&var self, 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(
&var self,
message: char8[..],
fields: Field[..]
)
pub func Error(&var self, message: char8[..])
Writes an Error record with no fields.
| Overload | Summary |
|---|---|
pub func Error(&var self, message: char8[..], fields: Field[..]) | Writes an Error record. |
pub func Error(&var self, message: char8[..]) | Writes an Error record with no fields. |
| Name | Type | Description |
|---|---|---|
message | char8[..] | what happened |
fields | Field[..] | the values that go with it |