+ 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 [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 ## GUI testing
- Seting TESTING variable runs application without backend dependency - Seting TESTING variable runs application without backend dependency
```shell ```shell
TESTING=true python application/albion-online-stats.py TESTING=simple python application/albion-online-stats.py
``` ```
# License # License
+18 -8
View File
@@ -1,8 +1,9 @@
use log::*;
use simplelog::*;
use std::env;
use std::fs::File; use std::fs::File;
use std::sync::mpsc::{channel, Receiver, Sender}; use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread; use std::thread;
use log::*;
use simplelog::*;
use packet_sniffer::UdpPacket; use packet_sniffer::UdpPacket;
use photon_decode::Photon; use photon_decode::Photon;
@@ -12,17 +13,14 @@ use crate::publisher::Publisher;
pub use crate::publisher::Subscribers; pub use crate::publisher::Subscribers;
use crate::translate::udp_packet_to_game_events; use crate::translate::udp_packet_to_game_events;
pub enum InitializationError { pub enum InitializationError {
NetworkInterfaceListMissing, NetworkInterfaceListMissing,
} }
pub fn initialize(subscribers: Subscribers) -> Result<(), InitializationError> { pub fn initialize(subscribers: Subscribers) -> Result<(), InitializationError> {
initialize_logging(); initialize_logging();
if let Ok(interfaces) = packet_sniffer::network_interfaces() { if let Ok(interfaces) = packet_sniffer::network_interfaces() {
thread::spawn(move || { thread::spawn(move || {
let (tx, rx): (Sender<UdpPacket>, Receiver<UdpPacket>) = channel(); let (tx, rx): (Sender<UdpPacket>, Receiver<UdpPacket>) = channel();
@@ -52,8 +50,20 @@ pub fn initialize(subscribers: Subscribers) -> Result<(), InitializationError> {
fn initialize_logging() { fn initialize_logging() {
CombinedLogger::init(vec![WriteLogger::new( CombinedLogger::init(vec![WriteLogger::new(
LevelFilter::Info, get_logging_level(),
Config::default(), Config::default(),
File::create("damage-meter.log").unwrap(), File::create("backend.log").unwrap(),
)]).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,
}
} }