-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from horizonx-tech/feature/logging
add logger
- Loading branch information
Showing
9 changed files
with
459 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...dk-macros/src/snapshots/chainsight_cdk_macros__utils__tests__snapshot__define_logger.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
source: chainsight-cdk-macros/src/utils.rs | ||
expression: formatted | ||
--- | ||
use chainsight_cdk::log::{Logger, LoggerImpl}; | ||
#[candid::candid_method(query)] | ||
#[ic_cdk::query] | ||
fn tail_logs(rows: usize) -> Vec<String> { | ||
_logger().tail(rows) | ||
} | ||
#[candid::candid_method(update)] | ||
#[ic_cdk::update] | ||
#[chainsight_cdk_macros::only_controller] | ||
fn drain_logs(rows: usize) -> Vec<String> { | ||
_logger().drain(rows) | ||
} | ||
#[ic_cdk::init] | ||
fn init_logger() { | ||
schedule_cleanup(); | ||
} | ||
#[ic_cdk::post_upgrade] | ||
fn post_upgrade_logger() { | ||
schedule_cleanup(); | ||
} | ||
fn schedule_cleanup() { | ||
ic_cdk_timers::set_timer_interval(std::time::Duration::from_secs(86400u64), || { | ||
ic_cdk::spawn(async { | ||
_logger().sweep(7u8); | ||
}) | ||
}); | ||
_logger().info( | ||
format!( | ||
"cleanup sheduled: interval = {} sec. retention days = {}", | ||
86400u64, 7u8 | ||
) | ||
.as_str(), | ||
); | ||
} | ||
fn _logger() -> LoggerImpl { | ||
LoggerImpl::new(Some("Logger")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod env; | ||
mod time; | ||
pub use core::*; | ||
pub use env::*; | ||
pub use time::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.