Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Jul 16, 2022
2 parents a4c1cee + d4ffafe commit 4271997
Show file tree
Hide file tree
Showing 27 changed files with 274 additions and 265 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ the fast log . This crate uses #! [forbid(unsafe_code)] to ensure everything is

A log implementation for extreme speed, using Crossbeam/channel ,once Batch write logs,fast log date, Appender architecture, appender per thread

* Low overhead, based on thread
* Low overhead, log write based on thread, also support tokio/Future

* High performance, use lockless message queue, log is stored in queue, then flush disk. It does not block the caller

Expand Down
8 changes: 4 additions & 4 deletions example/src/bench_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fast_log::appender::{LogAppender, FastLogRecord};
use std::time::{Instant};
use fast_log::appender::{FastLogRecord, LogAppender};
use fast_log::bencher::QPS;
use fast_log::config::Config;
use std::time::Instant;

/// cargo run --release --package example --bin bench_test
fn main() {
Expand All @@ -11,7 +11,7 @@ fn main() {
//nothing
}
}
fast_log::init(Config::new().custom(BenchRecvLog{})).unwrap();
fast_log::init(Config::new().custom(BenchRecvLog {})).unwrap();
let total = 1000000;
let now = Instant::now();
for index in 0..total {
Expand All @@ -21,4 +21,4 @@ fn main() {
log::logger().flush();
now.time(total);
now.qps(total);
}
}
4 changes: 2 additions & 2 deletions example/src/bench_test_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::{Instant};
use fast_log::bencher::QPS;
use fast_log::config::Config;
use std::time::Instant;

/// cargo run --release --package example --bin bench_test_file
fn main() {
Expand All @@ -16,4 +16,4 @@ fn main() {
log::logger().flush();
now.time(total);
now.qps(total);
}
}
17 changes: 10 additions & 7 deletions example/src/bench_test_file_split.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use std::time::Instant;
use fast_log::bencher::QPS;
use fast_log::config::Config;
use fast_log::consts::LogSize;
use fast_log::plugin::file_split::RollingType;
use fast_log::plugin::packer::LogPacker;
use std::time::Instant;

/// cargo run --release --package example --bin bench_test_file_split
fn main() {
//clear data
let _=std::fs::remove_dir("target/logs/");
fast_log::init(Config::new().file_split("target/logs/",
LogSize::MB(1),
RollingType::All,
LogPacker{})).unwrap();
let _ = std::fs::remove_dir("target/logs/");
fast_log::init(Config::new().file_split(
"target/logs/",
LogSize::MB(1),
RollingType::All,
LogPacker {},
))
.unwrap();
log::info!("Commencing yak shaving{}", 0);
let total = 1000000;
let now = Instant::now();
Expand All @@ -23,4 +26,4 @@ fn main() {
log::logger().flush();
now.time(total);
now.qps(total);
}
}
12 changes: 4 additions & 8 deletions example/src/custom_appender.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fast_log::appender::{LogAppender, FastLogRecord};
use log::Level;
use chrono::{DateTime, Local};
use fast_log::appender::{FastLogRecord, LogAppender};
use fast_log::config::Config;
use log::Level;

struct CustomLog {}

Expand All @@ -14,11 +14,7 @@ impl LogAppender for CustomLog {
Level::Warn | Level::Error => {
data = format!(
"{} {} {} - {} {}\n",
now,
record.level,
record.module_path,
record.args,
record.formated
now, record.level, record.module_path, record.args, record.formated
);
}
_ => {
Expand All @@ -38,4 +34,4 @@ fn main() {
log::info!("Commencing yak shaving");
log::error!("Commencing error");
log::logger().flush();
}
}
40 changes: 20 additions & 20 deletions example/src/custom_appender_meilisearch.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::sync::Arc;
use fast_log::appender::{LogAppender, FastLogRecord};
use log::Level;
use chrono::{DateTime, Local};
use fast_log::appender::{FastLogRecord, LogAppender};
use fast_log::config::Config;
use log::Level;
use meilisearch_sdk::client::Client;
use meilisearch_sdk::document::Document;
use fast_log::config::Config;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
use std::sync::Arc;

#[derive(Serialize, Deserialize, Debug)]
struct LogDoc {
Expand All @@ -22,7 +22,6 @@ impl Document for LogDoc {
}
}


/// you should download run [download](https://github.com/meilisearch/Meilisearch/releases)
///
/// or use docker command run meilisearch
Expand All @@ -32,18 +31,23 @@ impl Document for LogDoc {
#[tokio::main]
async fn main() {
let client = Client::new("http://localhost:7700", "masterKey");
fast_log::init(Config::new().custom(CustomLog {
c: Arc::new(client),
rt: tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap(),
})).unwrap();
fast_log::init(
Config::new().custom(CustomLog {
c: Arc::new(client),
rt: tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap(),
}),
)
.unwrap();
for index in 0..1000 {
log::info!("Commencing yak shaving:{}",index);
log::error!("Commencing error:{}",index);
log::info!("Commencing yak shaving:{}", index);
log::error!("Commencing error:{}", index);
}
log::logger().flush();
}


struct CustomLog {
c: Arc<Client>,
rt: tokio::runtime::Runtime,
Expand All @@ -58,11 +62,7 @@ impl LogAppender for CustomLog {
Level::Warn | Level::Error => {
data = format!(
"{} {} {} - {} {}\n",
now,
record.level,
record.module_path,
record.args,
record.formated
now, record.level, record.module_path, record.args, record.formated
);
}
_ => {
Expand All @@ -75,7 +75,7 @@ impl LogAppender for CustomLog {
let id = now.timestamp_millis() as usize;
let c = self.c.clone();
self.rt.block_on(async move {
println!("id:{}",id);
println!("id:{}", id);
let doc = c.index("LogDoc");
//send to web,file,any way
let log = LogDoc {
Expand All @@ -90,4 +90,4 @@ impl LogAppender for CustomLog {
});
}
}
}
}
28 changes: 15 additions & 13 deletions example/src/custom_appender_tokio.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use fast_log::appender::{LogAppender, FastLogRecord};
use log::Level;
use chrono::{DateTime, Local};
use tokio::runtime::Runtime;
use fast_log::appender::{FastLogRecord, LogAppender};
use fast_log::config::Config;
use log::Level;
use tokio::runtime::Runtime;

struct CustomLog {
rt:Runtime
rt: Runtime,
}

impl LogAppender for CustomLog {
Expand All @@ -18,11 +18,7 @@ impl LogAppender for CustomLog {
Level::Warn | Level::Error => {
data = format!(
"{} {} {} - {} {}\n",
now,
record.level,
record.module_path,
record.args,
record.formated
now, record.level, record.module_path, record.args, record.formated
);
}
_ => {
Expand All @@ -43,10 +39,16 @@ impl LogAppender for CustomLog {

#[tokio::main]
async fn main() {
fast_log::init(Config::new().custom(CustomLog {
rt: tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap()
})).unwrap();
fast_log::init(
Config::new().custom(CustomLog {
rt: tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap(),
}),
)
.unwrap();
log::info!("Commencing yak shaving");
log::error!("Commencing error");
log::logger().flush();
}
}
13 changes: 8 additions & 5 deletions example/src/format_log.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use log::LevelFilter;
use fast_log::appender::FastLogFormat;
use fast_log::config::Config;
use log::LevelFilter;

fn main() {
fast_log::init(Config::new()
.format(FastLogFormat::new().set_display_line_level(LevelFilter::Trace)
).console()).unwrap();
fast_log::init(
Config::new()
.format(FastLogFormat::new().set_display_line_level(LevelFilter::Trace))
.console(),
)
.unwrap();
log::info!("Commencing yak shaving{}", 0);
log::logger().flush();
}
}
2 changes: 1 addition & 1 deletion example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fn main() {
log::info!("Commencing yak shaving{}", 0);
fast_log::print("Commencing print\n".into()).expect("fast log not init");
log::logger().flush();
}
}
23 changes: 12 additions & 11 deletions example/src/split_log.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use fast_log::config::Config;
use fast_log::consts::LogSize;
use fast_log::plugin::file_split::RollingType;
use fast_log::plugin::packer::{LogPacker};
use fast_log::config::Config;
use fast_log::plugin::packer::LogPacker;

fn main(){
fast_log::init(Config::new()
.console()
.file_split("target/logs/",
LogSize::MB(1),
RollingType::All,
LogPacker{})).unwrap();
fn main() {
fast_log::init(Config::new().console().file_split(
"target/logs/",
LogSize::MB(1),
RollingType::All,
LogPacker {},
))
.unwrap();
for _ in 0..20000 {
log::info!("Commencing yak shaving");
}
log::logger().flush();
println!("you can see log files in path: {}","target/logs/")
}
println!("you can see log files in path: {}", "target/logs/")
}
23 changes: 12 additions & 11 deletions example/src/split_log_flush.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use fast_log::config::Config;
use fast_log::consts::LogSize;
use fast_log::plugin::file_split::RollingType;
use fast_log::plugin::packer::{LogPacker};
use fast_log::config::Config;
use fast_log::plugin::packer::LogPacker;

fn main(){
fast_log::init(Config::new()
.console()
.file_split("target/logs/",
LogSize::MB(1),
RollingType::All,
LogPacker{})).unwrap();
fn main() {
fast_log::init(Config::new().console().file_split(
"target/logs/",
LogSize::MB(1),
RollingType::All,
LogPacker {},
))
.unwrap();
for _ in 0..20000 {
log::info!("Commencing yak shaving");
}
Expand All @@ -23,5 +24,5 @@ fn main(){
// /// wait.wait();
// ///
// wg.wait();
println!("you can see log files in path: {}","target/logs/")
}
println!("you can see log files in path: {}", "target/logs/")
}
21 changes: 11 additions & 10 deletions example/src/split_log_gz.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use fast_log::config::Config;
use fast_log::consts::LogSize;
use fast_log::plugin::file_split::RollingType;
use fast_log::config::Config;
use fast_log::plugin::packer::GZipPacker;

fn main(){
fast_log::init(Config::new()
.console()
.file_split("target/logs/",
LogSize::KB(50),
RollingType::KeepNum(5),
GZipPacker{})).unwrap();
fn main() {
fast_log::init(Config::new().console().file_split(
"target/logs/",
LogSize::KB(50),
RollingType::KeepNum(5),
GZipPacker {},
))
.unwrap();
for _ in 0..20000 {
log::info!("Commencing yak shaving");
}
log::logger().flush();
println!("you can see log files in path: {}","target/logs/")
}
println!("you can see log files in path: {}", "target/logs/")
}
Loading

0 comments on commit 4271997

Please sign in to comment.