mirror of
https://github.com/jayofelony/pwnagotchi.git
synced 2025-07-01 18:37:27 -04:00
changes to logging and threading
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
*.pyc
|
@ -4,7 +4,8 @@ import os
|
|||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
import _thread
|
#import _thread
|
||||||
|
import threading
|
||||||
|
|
||||||
import pwnagotchi
|
import pwnagotchi
|
||||||
import pwnagotchi.utils as utils
|
import pwnagotchi.utils as utils
|
||||||
@ -304,7 +305,8 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def start_session_fetcher(self):
|
def start_session_fetcher(self):
|
||||||
_thread.start_new_thread(self._fetch_stats, ())
|
#_thread.start_new_thread(self._fetch_stats, ())
|
||||||
|
threading.Thread(target=self._fetch_stats, args=(), name="Session Fetcher").start()
|
||||||
|
|
||||||
def _fetch_stats(self):
|
def _fetch_stats(self):
|
||||||
while True:
|
while True:
|
||||||
@ -387,7 +389,8 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
|
|||||||
|
|
||||||
def start_event_polling(self):
|
def start_event_polling(self):
|
||||||
# start a thread and pass in the mainloop
|
# start a thread and pass in the mainloop
|
||||||
_thread.start_new_thread(self._event_poller, (asyncio.get_event_loop(),))
|
#_thread.start_new_thread(self._event_poller, (asyncio.get_event_loop(),))
|
||||||
|
threading.Thread(target=self._event_poller, args=(asyncio.get_event_loop(),), name="Event Polling")
|
||||||
|
|
||||||
def is_module_running(self, module):
|
def is_module_running(self, module):
|
||||||
s = self.session()
|
s = self.session()
|
||||||
|
@ -111,7 +111,8 @@ class AsyncTrainer(object):
|
|||||||
return self._training_epochs
|
return self._training_epochs
|
||||||
|
|
||||||
def start_ai(self):
|
def start_ai(self):
|
||||||
_thread.start_new_thread(self._ai_worker, ())
|
#_thread.start_new_thread(self._ai_worker, ())
|
||||||
|
threading.Thread(target=self._ai_worker, args=(), name="AI Worker").start()
|
||||||
|
|
||||||
def _save_ai(self):
|
def _save_ai(self):
|
||||||
logging.info("[AI] saving model to %s ..." % self._nn_path)
|
logging.info("[AI] saving model to %s ..." % self._nn_path)
|
||||||
|
@ -112,6 +112,7 @@ main.mon_max_blind_epochs = 50
|
|||||||
main.no_restart = false
|
main.no_restart = false
|
||||||
|
|
||||||
main.log.path = "/etc/pwnagotchi/log/pwnagotchi.log"
|
main.log.path = "/etc/pwnagotchi/log/pwnagotchi.log"
|
||||||
|
main.log.path-debug = "/etc/pwnagotchi/log/pwnagotchi.log"
|
||||||
main.log.rotation.enabled = true
|
main.log.rotation.enabled = true
|
||||||
main.log.rotation.size = "10M"
|
main.log.rotation.size = "10M"
|
||||||
|
|
||||||
|
@ -217,25 +217,45 @@ class LastSession(object):
|
|||||||
def setup_logging(args, config):
|
def setup_logging(args, config):
|
||||||
cfg = config['main']['log']
|
cfg = config['main']['log']
|
||||||
filename = cfg['path']
|
filename = cfg['path']
|
||||||
|
filenameDebug = cfg['path']
|
||||||
|
|
||||||
formatter = logging.Formatter("[%(asctime)s] [%(levelname)s] %(message)s")
|
#global formatter
|
||||||
root = logging.getLogger()
|
formatter = logging.Formatter("[%(asctime)s] [%(levelname)s] [%(threadName)s] : %(message)s")
|
||||||
|
logger = logging.getLogger()
|
||||||
root.setLevel(logging.DEBUG if args.debug else logging.INFO)
|
|
||||||
|
for handler in logger.handlers:
|
||||||
|
handler.setLevel(logging.DEBUG if args.debug else logging.INFO)
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
|
||||||
|
|
||||||
|
logger.setLevel(logging.DEBUG if args.debug else logging.INFO)
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
# since python default log rotation might break session data in different files,
|
# since python default log rotation might break session data in different files,
|
||||||
# we need to do log rotation ourselves
|
# we need to do log rotation ourselves
|
||||||
log_rotation(filename, cfg)
|
log_rotation(filename, cfg)
|
||||||
|
log_rotation(filenameDebug, cfg)
|
||||||
|
|
||||||
file_handler = logging.FileHandler(filename)
|
|
||||||
file_handler.setFormatter(formatter)
|
|
||||||
root.addHandler(file_handler)
|
# File handler for logging all normal messages
|
||||||
|
file_handler = logging.FileHandler(filename) #creates new
|
||||||
|
file_handler.setLevel(logging.INFO)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
console_handler = logging.StreamHandler()
|
# File handler for logging all debug messages
|
||||||
console_handler.setFormatter(formatter)
|
file_handler = logging.FileHandler(filenameDebug) #creates new
|
||||||
root.addHandler(console_handler)
|
file_handler.setLevel(logging.DEBUG)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
|
# Console handler for logging debug messages if args.debug is true else just log normal
|
||||||
|
#console_handler = logging.StreamHandler() #creates new
|
||||||
|
#console_handler.setLevel(logging.DEBUG if args.debug else logging.INFO)
|
||||||
|
#console_handler.setFormatter(formatter)
|
||||||
|
#logger.addHandler(console_handler)
|
||||||
|
|
||||||
if not args.debug:
|
if not args.debug:
|
||||||
# disable scapy and tensorflow logging
|
# disable scapy and tensorflow logging
|
||||||
logging.getLogger("scapy").disabled = True
|
logging.getLogger("scapy").disabled = True
|
||||||
@ -250,6 +270,8 @@ def setup_logging(args, config):
|
|||||||
requests_log.prpagate = False
|
requests_log.prpagate = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def log_rotation(filename, cfg):
|
def log_rotation(filename, cfg):
|
||||||
rotation = cfg['rotation']
|
rotation = cfg['rotation']
|
||||||
if not rotation['enabled']:
|
if not rotation['enabled']:
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import _thread
|
#import _thread
|
||||||
|
import threading
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -41,7 +42,8 @@ class AsyncAdvertiser(object):
|
|||||||
|
|
||||||
def start_advertising(self):
|
def start_advertising(self):
|
||||||
if self._config['personality']['advertise']:
|
if self._config['personality']['advertise']:
|
||||||
_thread.start_new_thread(self._adv_poller, ())
|
#_thread.start_new_thread(self._adv_poller, ())
|
||||||
|
threading.Thread(target=self._adv_poller,args=(), name="Grid").start()
|
||||||
|
|
||||||
grid.set_advertisement_data(self._advertisement)
|
grid.set_advertisement_data(self._advertisement)
|
||||||
grid.advertise(True)
|
grid.advertise(True)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import _thread
|
import _thread
|
||||||
|
import threading
|
||||||
import glob
|
import glob
|
||||||
import importlib
|
import importlib
|
||||||
import importlib.util
|
import importlib.util
|
||||||
@ -95,8 +96,10 @@ def one(plugin_name, event_name, *args, **kwargs):
|
|||||||
if callback is not None and callable(callback):
|
if callback is not None and callable(callback):
|
||||||
try:
|
try:
|
||||||
lock_name = "%s::%s" % (plugin_name, cb_name)
|
lock_name = "%s::%s" % (plugin_name, cb_name)
|
||||||
|
loggingFormat = "%s.%s" % (plugin_name, cb_name)
|
||||||
locked_cb_args = (lock_name, callback, *args, *kwargs)
|
locked_cb_args = (lock_name, callback, *args, *kwargs)
|
||||||
_thread.start_new_thread(locked_cb, locked_cb_args)
|
#_thread.start_new_thread(locked_cb, locked_cb_args)
|
||||||
|
threading.Thread(target=locked_cb, args=locked_cb_args, name=loggingFormat).start()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("error while running %s.%s : %s" % (plugin_name, cb_name, e))
|
logging.error("error while running %s.%s : %s" % (plugin_name, cb_name, e))
|
||||||
logging.error(e, exc_info=True)
|
logging.error(e, exc_info=True)
|
||||||
|
@ -21,7 +21,8 @@ class Display(View):
|
|||||||
self._canvas_next = None
|
self._canvas_next = None
|
||||||
self._render_thread_instance = threading.Thread(
|
self._render_thread_instance = threading.Thread(
|
||||||
target=self._render_thread,
|
target=self._render_thread,
|
||||||
daemon=True
|
daemon=True,
|
||||||
|
name="Renderer"
|
||||||
)
|
)
|
||||||
self._render_thread_instance.start()
|
self._render_thread_instance.start()
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import _thread
|
#import _thread
|
||||||
|
import threading
|
||||||
import secrets
|
import secrets
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -25,7 +26,9 @@ class Server:
|
|||||||
self._origin = self._config['origin']
|
self._origin = self._config['origin']
|
||||||
|
|
||||||
if self._enabled:
|
if self._enabled:
|
||||||
_thread.start_new_thread(self._http_serve, ())
|
#_thread.start_new_thread(self._http_serve, ())
|
||||||
|
logging.info("Starting WebServer thread")
|
||||||
|
self._thread = threading.Thread(target=self._http_serve, name="WebServer").start()
|
||||||
|
|
||||||
def _http_serve(self):
|
def _http_serve(self):
|
||||||
if self._address is not None:
|
if self._address is not None:
|
||||||
|
Reference in New Issue
Block a user