1
1
use arc_swap:: { ArcSwap , Guard } ;
2
+ use log:: { error, info} ;
2
3
use once_cell:: sync:: Lazy ;
3
4
use serde_derive:: Deserialize ;
4
5
use tokio:: fs:: File ;
@@ -150,14 +151,14 @@ impl Default for Config {
150
151
151
152
impl Config {
152
153
pub fn show ( & self ) {
153
- println ! ( "> Pool size: {}" , self . general. pool_size) ;
154
- println ! ( "> Pool mode: {}" , self . general. pool_mode) ;
155
- println ! ( "> Ban time: {}s" , self . general. ban_time) ;
156
- println ! (
157
- "> Healthcheck timeout: {}ms" ,
154
+ info ! ( "Pool size: {}" , self . general. pool_size) ;
155
+ info ! ( "Pool mode: {}" , self . general. pool_mode) ;
156
+ info ! ( "Ban time: {}s" , self . general. ban_time) ;
157
+ info ! (
158
+ "Healthcheck timeout: {}ms" ,
158
159
self . general. healthcheck_timeout
159
160
) ;
160
- println ! ( "> Connection timeout: {}ms" , self . general. connect_timeout) ;
161
+ info ! ( "Connection timeout: {}ms" , self . general. connect_timeout) ;
161
162
}
162
163
}
163
164
@@ -171,23 +172,23 @@ pub async fn parse(path: &str) -> Result<(), Error> {
171
172
let mut file = match File :: open ( path) . await {
172
173
Ok ( file) => file,
173
174
Err ( err) => {
174
- println ! ( "> Config error: {:?}" , err) ;
175
+ error ! ( "{:?}" , err) ;
175
176
return Err ( Error :: BadConfig ) ;
176
177
}
177
178
} ;
178
179
179
180
match file. read_to_string ( & mut contents) . await {
180
181
Ok ( _) => ( ) ,
181
182
Err ( err) => {
182
- println ! ( "> Config error: {:?}" , err) ;
183
+ error ! ( "{:?}" , err) ;
183
184
return Err ( Error :: BadConfig ) ;
184
185
}
185
186
} ;
186
187
187
188
let config: Config = match toml:: from_str ( & contents) {
188
189
Ok ( config) => config,
189
190
Err ( err) => {
190
- println ! ( "> Config error: {:?}" , err) ;
191
+ error ! ( "{:?}" , err) ;
191
192
return Err ( Error :: BadConfig ) ;
192
193
}
193
194
} ;
@@ -200,7 +201,7 @@ pub async fn parse(path: &str) -> Result<(), Error> {
200
201
let mut primary_count = 0 ;
201
202
202
203
if shard. 1 . servers . len ( ) == 0 {
203
- println ! ( "> Shard {} has no servers configured" , shard. 0 ) ;
204
+ error ! ( "Shard {} has no servers configured" , shard. 0 ) ;
204
205
return Err ( Error :: BadConfig ) ;
205
206
}
206
207
@@ -218,8 +219,8 @@ pub async fn parse(path: &str) -> Result<(), Error> {
218
219
"primary" => ( ) ,
219
220
"replica" => ( ) ,
220
221
_ => {
221
- println ! (
222
- "> Shard {} server role must be either 'primary' or 'replica', got: '{}'" ,
222
+ error ! (
223
+ "Shard {} server role must be either 'primary' or 'replica', got: '{}'" ,
223
224
shard. 0 , server. 2
224
225
) ;
225
226
return Err ( Error :: BadConfig ) ;
@@ -228,12 +229,12 @@ pub async fn parse(path: &str) -> Result<(), Error> {
228
229
}
229
230
230
231
if primary_count > 1 {
231
- println ! ( "> Shard {} has more than on primary configured. " , & shard. 0 ) ;
232
+ error ! ( "Shard {} has more than on primary configured" , & shard. 0 ) ;
232
233
return Err ( Error :: BadConfig ) ;
233
234
}
234
235
235
236
if dup_check. len ( ) != shard. 1 . servers . len ( ) {
236
- println ! ( "> Shard {} contains duplicate server configs. " , & shard. 0 ) ;
237
+ error ! ( "Shard {} contains duplicate server configs" , & shard. 0 ) ;
237
238
return Err ( Error :: BadConfig ) ;
238
239
}
239
240
}
@@ -243,8 +244,8 @@ pub async fn parse(path: &str) -> Result<(), Error> {
243
244
"primary" => ( ) ,
244
245
"replica" => ( ) ,
245
246
other => {
246
- println ! (
247
- "> Query router default_role must be 'primary', 'replica', or 'any', got: '{}'" ,
247
+ error ! (
248
+ "Query router default_role must be 'primary', 'replica', or 'any', got: '{}'" ,
248
249
other
249
250
) ;
250
251
return Err ( Error :: BadConfig ) ;
0 commit comments