Struct dittolive_ditto::logger::DittoLogger
source · pub struct DittoLogger(/* private fields */);
Expand description
Type with free associated functions (“static methods”) to customize the logging behavior from Ditto and log messages with the Ditto logging infrastructure.
Implementations§
source§impl DittoLogger
impl DittoLogger
sourcepub fn set_logging_enabled(enabled: bool)
pub fn set_logging_enabled(enabled: bool)
Enable or disable logging.
Logs exported through [export_to_file
] are not affected by this
setting and will also include logs emitted while enabled
is false.
sourcepub fn get_logging_enabled() -> bool
pub fn get_logging_enabled() -> bool
Return true if logging is enabled.
Logs exported through [export_to_file
] are not affected by this
setting and will also include logs emitted while enabled
is false.
sourcepub fn get_emoji_log_level_headings_enabled() -> bool
pub fn get_emoji_log_level_headings_enabled() -> bool
Represent whether or not emojis should be used as the log level indicator in the logs.
sourcepub fn set_emoji_log_level_headings_enabled(enabled: bool)
pub fn set_emoji_log_level_headings_enabled(enabled: bool)
Set whether or not emojis should be used as the log level indicator in the logs.
sourcepub fn get_minimum_log_level() -> LogLevel
pub fn get_minimum_log_level() -> LogLevel
Get the current minimum log level.
Logs exported through [export_to_file
] are not affected by this
setting and include all logs at LogLevel::Warning
and above.
sourcepub fn set_minimum_log_level(log_level: LogLevel)
pub fn set_minimum_log_level(log_level: LogLevel)
Set the current minimum log level.
Logs exported through [export_to_file
] are not affected by this
setting and include all logs at LogLevel::Warning
and above.
source§impl DittoLogger
impl DittoLogger
sourcepub async fn export_to_file(
file_path: &(impl ?Sized + AsRef<Path>)
) -> Result<u64>
pub async fn export_to_file( file_path: &(impl ?Sized + AsRef<Path>) ) -> Result<u64>
Exports collected logs to a compressed and JSON-encoded file on the local file system.
DittoLogger
locally collects a limited amount of logs at the LogLevel::Debug
level and above, periodically discarding old logs. The internal logger is
always enabled and workds independently of the enabled
setting and the
configured minimum_log_level
. Its logs can be requested and downloaded
from any peer that is active in a Ditto app using the portal’s device
dashboard. This method provides an alternative way of accessing those
logs by exporting them to the local filesystem.
The logs will be written as a gzip compressed file at the URL specified
by the file_path
parameter. When uncompressed, the file contains one
JSON value per line with the oldest entry on the first line (JSON lines
format).
Ditto limits the amount of logs it retains on disk to 15 MB and a maximum age of three days. Older logs are periodically discarded once one of these limits is reached.
This method currently only exports logs from the most recently created Ditto instance, even when multiple instances are running in the same process.
This method currently only exports logs from the most recently created Ditto instance when multiple instances are running in the same process.
-
Parameter
file_path
: the path of the file to write the logs to. The file must not already exist, and the containing directory must exist. It is recommended for the path to have the.jsonl.gz
file extension but Ditto won’t enforce it, nor correct it. -
Errors: it can run into I/O errors when the file cannot be written to disk. Prevent this by ensuring that no file exists at the provided path, all parent directories exist, sufficient permissions are granted, and that the disk is not full.
More precisely, this “throws” a
DittoError
whose.kind()
is that of anErrorKind::CoreApi
, such as: -
Returns: the number of bytes written to disk.
Example
use ::dittolive_ditto::{
error::{CoreApiErrorKind, ErrorKind},
prelude::*,
};
let ditto: Ditto = /* construct at least one ditto instance first */
match DittoLogger::export_to_file("/some/path.jsonl.gz").await {
Ok(_bytes_written) => { /* … */ },
Err(err) => match err.kind() {
ErrorKind::CoreApi(CoreApiErrorKind::IoNotFound) => { /* … */ },
ErrorKind::CoreApi(CoreApiErrorKind::IoPermissionDenied) => { /* … */ },
ErrorKind::CoreApi(CoreApiErrorKind::IoAlreadyExists) => { /* … */ },
ErrorKind::CoreApi(CoreApiErrorKind::IoOperationFailed) => { /* … */ },
_ => error!("{err}"),
},
}