Skip to content

Commit 76f8413

Browse files
author
chenjunliang
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/daemon_util.rs # src/libc_util.rs
2 parents b9a2d60 + 0e870f2 commit 76f8413

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "mysql-audit-extend"
3-
version = "0.2.4"
3+
version = "0.2.5"
44
edition = "2021"
55
authors = ["seeker"]
66
description = "An extension tool of mysql-audit, which provides functions such as log rotation and log cleaning."
77
license = "MIT"
8-
documentation = "https://docs.rs/crate/mysql-audit-extend/0.2.4"
8+
documentation = "https://docs.rs/crate/mysql-audit-extend/0.2.5"
99
repository = "https://gitee.com/seeker_rs/mysql-audit-extend"
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cargo install mysql-audit-extend
1111
```
1212
or
1313
```shell
14-
wget https://gitee.com/seeker_rs/mysql-audit-extend/releases/download/release-0.2.4/mysql-audit-extend
14+
wget https://gitee.com/seeker_rs/mysql-audit-extend/releases/download/release-0.2.5/mysql-audit-extend
1515
chmod 775 mysql-audit-extend
1616
```
1717

src/daemon_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::fs;
77
#[cfg(target_family = "unix")]
88
use std::fs::File;
99

10+
/// Linux background running
1011
#[cfg(target_family = "unix")]
1112
pub fn daemonize(
1213
username: &str,

src/libc_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[cfg(target_family = "unix")]
22
use users::{get_current_uid, get_user_by_uid};
33

4+
/// Get current operating system user
45
#[cfg(target_family = "unix")]
56
pub fn get_current_user() -> String {
67
let user = get_user_by_uid(get_current_uid()).unwrap();

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ struct Options {
2626
max_file: u32,
2727
}
2828

29-
/// 文件路径检查
29+
/// File path check
3030
fn parse_path(s: &str) -> Result<String> {
3131
fs::File::open(s)?;
3232
Ok(s.into())
3333
}
3434

35+
/// Initialize the log component
3536
fn init_log() {
3637
simple_logger::init_with_level(log::Level::Info).unwrap();
3738
}
3839

40+
/// main function
3941
fn main() -> Result<()> {
4042
let options = Options::parse();
4143
log::info!("App environments:{:?}", options);

src/tasks.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ use std::path::Path;
77
use std::thread::sleep;
88
use std::time::{Duration};
99

10-
fn mysql_audit_log_rotate(sched: &mut JobScheduler, path: String, max_size: u32, max_file: u32) {
11-
// utc time
10+
/// Handling mysql audit logs
11+
fn mysql_audit_log_handle(sched: &mut JobScheduler, path: String, max_size: u32, max_file: u32) {
1212
sched.add(Job::new("1/10 * * * * *".parse().unwrap(), move || {
1313
let r = fs::File::options().write(true).open(path.as_str());
1414
match r {
1515
Ok(file) => {
1616
let metadata = file.metadata().unwrap();
1717
let file_len = Decimal::from(metadata.len());
1818
let cf = Decimal::from(1024);
19-
let file_size = (file_len / cf / cf).round_dp(0);
19+
let file_size = (file_len / cf / cf).round_dp(2);
2020
let file_max_size = Decimal::from(max_size);
2121
if file_size >= file_max_size {
2222
log::info!("The file size reaches the split standard:{:?}M", file_size);
@@ -65,10 +65,11 @@ fn mysql_audit_log_rotate(sched: &mut JobScheduler, path: String, max_size: u32,
6565
}));
6666
}
6767

68+
/// Scheduled task control
6869
pub fn start_backstage_task(path: String, max_size: u32, max_file: u32) {
6970
let mut sched = JobScheduler::new();
7071

71-
mysql_audit_log_rotate(sched.borrow_mut(), path, max_size, max_file);
72+
mysql_audit_log_handle(sched.borrow_mut(), path, max_size, max_file);
7273

7374
loop {
7475
sched.tick();

0 commit comments

Comments
 (0)