Skip to content

Commit

Permalink
feat: add ability to disable file logging
Browse files Browse the repository at this point in the history
  • Loading branch information
madelynwith5ns committed May 23, 2024
1 parent 0f2c5e8 commit c669791
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ crate-type = [ "dylib", "lib" ]
[dependencies]

[features]
default = [ "workers" ]
multilog = [ ]
default = [ "workers", "file-log" ]
file-log = [ ]
multilog = [ "file-log" ]
workers = [ ]
35 changes: 21 additions & 14 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,30 +181,35 @@ macro_rules! sinput {
pub fn init() {
// if we already have a log file the user is being naughty and calling
// this more than once.
let read = match LOG_FILE.read() {
Ok(file) => file,
Err(_) => {
#[cfg(feature = "file-log")]
{
let read = match LOG_FILE.read() {
Ok(file) => file,
Err(_) => {
VANESSA_LOGGER.log(
LogLevel::ERROR,
format!("cannot acquire log file. can't be initialized."),
);
return;
}
};
if read.is_some() {
VANESSA_LOGGER.log(
LogLevel::ERROR,
format!("cannot acquire log file. can't be initialized."),
format!("vanessa::log::init() called more than once. Don't do that."),
);
return;
}
};
if read.is_some() {
VANESSA_LOGGER.log(
LogLevel::ERROR,
format!("vanessa::log::init() called more than once. Don't do that."),
);
return;
// if we dont drop this the real inits get caught forever
// waiting for it to drop
drop(read);
}
// if we dont drop this the real inits get caught forever
// waiting for it to drop
drop(read);

#[cfg(feature = "multilog")]
#[cfg(feature = "file-log")]
init_multi_log();
#[cfg(not(feature = "multilog"))]
#[cfg(feature = "file-log")]
init_single_log();
}

Expand Down Expand Up @@ -420,13 +425,15 @@ impl Logger<'_> {

// remove the newline
input = input.replace("\n", "");
#[cfg(feature = "file-log")]
self.log_file(&timestamp, level, &format!("{} {}", &text, &input));
return Some(input);
}

if level >= self.tlevel {
self.log_term(&timestamp, level, &text);
}
#[cfg(feature = "file-log")]
if level >= self.flevel {
self.log_file(&timestamp, level, &text);
}
Expand Down

0 comments on commit c669791

Please sign in to comment.