Skip to content

Commit b05aae2

Browse files
committed
[#184] 로거를 env_logger로 교체
1 parent adeb88a commit b05aae2

File tree

9 files changed

+22
-54
lines changed

9 files changed

+22
-54
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ itertools = "0.10.5"
3838
anyhow = "1.0.86"
3939
mockall = "0.12.1"
4040
bitcode = "0.6.3"
41+
env_logger = "0.11.8"
42+
log = "0.4.28"
4143

4244
[target.'cfg(windows)'.dependencies]
4345
winreg = "0.10.1"
@@ -57,4 +59,4 @@ rrdb = ["cli"]
5759
cli = ["atty", "structopt"]
5860

5961
[lints.clippy]
60-
to_string_trait_impl = "allow"
62+
to_string_trait_impl = "allow"

src/engine/lexer/tokenizer.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::errors::predule::LexingError;
2-
use crate::errors::RRDBError;
31
use crate::engine::lexer::predule::{OperatorToken, Token};
4-
use crate::logger::predule::Logger;
2+
use crate::errors::RRDBError;
3+
use crate::errors::predule::LexingError;
54

65
#[derive(Debug)]
76
pub struct Tokenizer {
@@ -12,7 +11,7 @@ pub struct Tokenizer {
1211

1312
impl Tokenizer {
1413
pub fn new(text: String) -> Self {
15-
Logger::info(format!("SQL echo: {:?}", text));
14+
log::info!("SQL echo: {:?}", text);
1615
Self {
1716
last_char: ' ',
1817
buffer: text.chars().collect(),
@@ -207,7 +206,7 @@ impl Tokenizer {
207206
return Err(LexingError::wrap(format!(
208207
"invalid floating point number format: {}",
209208
number_string
210-
)))
209+
)));
211210
}
212211
}
213212
} else {
@@ -219,7 +218,7 @@ impl Tokenizer {
219218
return Err(LexingError::wrap(format!(
220219
"invalid integer number format: {}",
221220
number_string
222-
)))
221+
)));
223222
}
224223
}
225224
}
@@ -328,7 +327,7 @@ impl Tokenizer {
328327
return Err(LexingError::wrap(format!(
329328
"unexpected operator: {:?}",
330329
self.last_char
331-
)))
330+
)));
332331
}
333332
}
334333
}

src/engine/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::engine::wal::endec::implements::bitcode::BitcodeEncoder;
3131
use crate::engine::wal::manager::WALManager;
3232
use crate::errors::RRDBError;
3333
use crate::errors::execute_error::ExecuteError;
34-
use crate::logger::predule::Logger;
3534

3635
pub struct DBEngine {
3736
pub(crate) config: Arc<LaunchConfig>,
@@ -55,7 +54,7 @@ impl DBEngine {
5554
_wal_manager: Arc<WALManager<BitcodeEncoder>>,
5655
_connection_id: String,
5756
) -> Result<ExecuteResult, RRDBError> {
58-
Logger::info(format!("AST echo: {:?}", statement));
57+
log::info!("AST echo: {:?}", statement);
5958

6059
// 쿼리 실행
6160
let result = match statement {

src/engine/server/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::engine::wal::endec::implements::bitcode::{BitcodeDecoder, BitcodeEnco
1313
use crate::engine::wal::manager::builder::WALBuilder;
1414
use crate::errors::RRDBError;
1515
use crate::errors::execute_error::ExecuteError;
16-
use crate::logger::predule::Logger;
1716
use crate::pgwire::predule::Connection;
1817

1918
use futures::future::join_all;
@@ -74,15 +73,15 @@ impl Server {
7473
.response_sender
7574
.send(ChannelResponse { result: Ok(result) })
7675
{
77-
Logger::error("channel send failed");
76+
log::error!("channel send failed");
7877
}
7978
}
8079
Err(error) => {
8180
let error = error.to_string();
8281
if let Err(_response) = request.response_sender.send(ChannelResponse {
8382
result: Err(ExecuteError::wrap(error)),
8483
}) {
85-
Logger::error("channel send failed");
84+
log::error!("channel send failed");
8685
}
8786
}
8887
}
@@ -104,7 +103,7 @@ impl Server {
104103
let (stream, address) = match accepted {
105104
Ok((stream, address)) => (stream, address),
106105
Err(error) => {
107-
Logger::error(format!("socket error {:?}", error));
106+
log::error!("socket error {:?}", error);
108107
continue;
109108
}
110109
};
@@ -124,16 +123,17 @@ impl Server {
124123
tokio::spawn(async move {
125124
let mut conn = Connection::new(shared_state, config);
126125
if let Err(error) = conn.run(stream).await {
127-
Logger::error(format!("connection error {:?}", error));
126+
log::error!("connection error {:?}", error);
128127
}
129128
});
130129
}
131130
});
132131

133-
Logger::info(format!(
132+
log::info!(
134133
"Server is running on {}:{}",
135-
self.config.host, self.config.port
136-
));
134+
self.config.host,
135+
self.config.port
136+
);
137137

138138
join_all(vec![connection_task, background_task]).await;
139139

src/logger/logger.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/logger/mod.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/logger/predule.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod config;
44
pub mod constants;
55
pub mod engine;
66
pub mod errors;
7-
pub mod logger;
87
pub mod pgwire;
98
pub mod utils;
109

@@ -20,6 +19,8 @@ use crate::{
2019

2120
#[tokio::main]
2221
async fn main() -> Result<(), RRDBError> {
22+
env_logger::init();
23+
2324
let args = Command::parse();
2425

2526
match args.action {

src/pgwire/connection/connection.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::engine::lexer::predule::Tokenizer;
1212
use crate::engine::parser::context::ParserContext;
1313
use crate::engine::parser::predule::Parser;
1414
use crate::engine::server::shared_state::SharedState;
15-
use crate::logger::predule::Logger;
1615
use crate::pgwire::connection::{BoundPortal, ConnectionError, ConnectionState, PreparedStatement};
1716
use crate::pgwire::engine::{Engine, Portal, RRDBEngine};
1817
use crate::pgwire::protocol::backend::{
@@ -120,12 +119,12 @@ impl Connection {
120119
self.engine.shared_state.client_info.database =
121120
database_name.to_owned();
122121

123-
Logger::info(format!(
122+
log::info!(
124123
"New Connection=> UUID:{} IP:{} DATABASE:{}",
125124
self.engine.shared_state.client_info.connection_id,
126125
self.engine.shared_state.client_info.ip,
127126
self.engine.shared_state.client_info.database
128-
));
127+
);
129128
} else {
130129
return Err(ErrorResponse::fatal(
131130
SqlState::CONNECTION_EXCEPTION,

0 commit comments

Comments
 (0)