+ dynamic debug logging
This commit is contained in:
@@ -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
|
||||
|
||||
+18
-8
@@ -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();
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user