+ dynamic debug logging

This commit is contained in:
Wiktor Mazur
2020-03-07 13:49:51 +01:00
parent cc3c1e10e2
commit 5c1b50ea51
2 changed files with 35 additions and 14 deletions
+12 -1
View File
@@ -84,11 +84,22 @@ After first execution the app is going to create default configuration file name
[sudo on linux] python application/albion-online-stats.py
```
## Debugging
Setting `BACKEND_LOG_LEVEL` to `DEBUG` value enables more advanced debug information
E.g
```shell
BACKEND_LOG_LEVEL=DEBUG python application/albion-online-stats.py
```
## GUI testing
- Seting TESTING variable runs application without backend dependency
```shell
TESTING=true python application/albion-online-stats.py
TESTING=simple python application/albion-online-stats.py
```
# License
+23 -13
View File
@@ -1,8 +1,9 @@
use log::*;
use simplelog::*;
use std::env;
use std::fs::File;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread;
use log::*;
use simplelog::*;
use packet_sniffer::UdpPacket;
use photon_decode::Photon;
@@ -12,17 +13,14 @@ use crate::publisher::Publisher;
pub use crate::publisher::Subscribers;
use crate::translate::udp_packet_to_game_events;
pub enum InitializationError {
NetworkInterfaceListMissing,
}
pub fn initialize(subscribers: Subscribers) -> Result<(), InitializationError> {
initialize_logging();
if let Ok(interfaces) = packet_sniffer::network_interfaces() {
thread::spawn(move || {
let (tx, rx): (Sender<UdpPacket>, Receiver<UdpPacket>) = channel();
@@ -36,10 +34,10 @@ pub fn initialize(subscribers: Subscribers) -> Result<(), InitializationError> {
loop {
if let Ok(packet) = rx.recv() {
udp_packet_to_game_events(&mut world, &mut photon, &packet)
.into_iter()
.for_each(|e| {
publisher.publish(&e);
});
.into_iter()
.for_each(|e| {
publisher.publish(&e);
});
}
}
});
@@ -52,8 +50,20 @@ pub fn initialize(subscribers: Subscribers) -> Result<(), InitializationError> {
fn initialize_logging() {
CombinedLogger::init(vec![WriteLogger::new(
LevelFilter::Info,
get_logging_level(),
Config::default(),
File::create("damage-meter.log").unwrap(),
)]).unwrap();
}
File::create("backend.log").unwrap(),
)])
.unwrap();
}
fn get_logging_level() -> LevelFilter {
match env::var("BACKEND_LOG_LEVEL")
.unwrap_or("INFO".into())
.to_lowercase()
.as_str()
{
"debug" => LevelFilter::Debug,
_ => LevelFilter::Info,
}
}