Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging Overhaul #947

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
18 changes: 13 additions & 5 deletions octoprint_mrbeam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
import time
import collections
from subprocess import check_output
import logging

from octoprint_mrbeam.mrb_logger import init_mrb_logger, getLogger, MrbLogger
# Hacky - Set the default logging class to MrbLogger asap
# Allows to use the analytics handler and/or the terminal kwargs
logging.setLoggerClass(MrbLogger)


import octoprint.plugin
import requests
Expand Down Expand Up @@ -44,7 +51,6 @@
from octoprint_mrbeam.analytics.review_handler import reviewHandler
from octoprint_mrbeam.led_events import LedEventListener
from octoprint_mrbeam.mrbeam_events import MrBeamEvents
from octoprint_mrbeam.mrb_logger import init_mrb_logger, mrb_logger
from octoprint_mrbeam.migrate import migrate
from octoprint_mrbeam.os_health_care import os_health_care
from octoprint_mrbeam.wizard_config import WizardConfig
Expand All @@ -58,6 +64,7 @@
from .analytics.uploader import AnalyticsFileUploader
from octoprint.filemanager.destinations import FileDestinations
from octoprint_mrbeam.util.material_csv_parser import parse_csv
from octoprint_mrbeam.util.log import force_getLogger
from octoprint_mrbeam.util.calibration_marker import CalibrationMarker
from octoprint_mrbeam.camera.undistort import MIN_MARKER_PIX
from octoprint_mrbeam.util.device_info import deviceInfo
Expand Down Expand Up @@ -122,8 +129,7 @@ def __init__(self):
self._cancel_job = False
self.print_progress_last = -1
self.slicing_progress_last = -1
self._logger = mrb_logger("octoprint.plugins.mrbeam")

self._logger = getLogger(__name__)
self._device_info = deviceInfo(use_dummy_values=IS_X86)
self._hostname = None # see self.getHosetname()
self._serial_num = None
Expand All @@ -146,8 +152,11 @@ def __init__(self):
# inside initialize() OctoPrint is already loaded, not assured during __init__()!
def initialize(self):
self._plugin_version = __version__
logging.setLoggerClass(MrbLogger)
# Force use the MrbLogger, because initialize is run directly from Octoprint
self._logger = force_getLogger(__name__, MrbLogger)
# _logger = getLogger(__name__)
init_mrb_logger(self._printer)
self._logger = mrb_logger("octoprint.plugins.mrbeam")
self._branch = self.getBranch()
self._octopi_info = self.get_octopi_info()
self._serial_num = self.getSerialNum()
Expand Down Expand Up @@ -202,7 +211,6 @@ def initialize(self):
self._logger.info('MrBeamPlugin initialized!')
self.mrbeam_plugin_initialized = True
self.fire_event(MrBeamEvents.MRB_PLUGIN_INITIALIZED)

self._do_initial_log()

def _do_initial_log(self):
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/analytics/analytics_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, plugin):
self._plugin_version = plugin.get_plugin_version()

self._timer_handler = TimerHandler(plugin, self, self._analytics_lock)
self._logger = mrb_logger("octoprint.plugins.mrbeam.analytics.analyticshandler")
self._logger = mrb_logger(__name__)

# Mr Beam specific data
self._analytics_enabled = self._settings.get(['analyticsEnabled'])
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/analytics/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Cpu(object):
SAVE_TEMP_INTERVAL = 60.0

def __init__(self, state=None, repeat=False, interval=None):
self._logger = mrb_logger("octoprint.plugins.mrbeam.analytics.cpu")
self._logger = mrb_logger(__name__)
self._temp = {}
self._throttle_warnings = []
self._progress = None
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/analytics/review_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def reviewHandler(plugin):

class ReviewHandler:
def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.analytics.review")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self._event_bus = plugin._event_bus
self._settings = plugin._settings
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/analytics/timer_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TimerHandler:
ONLINE_CHECK_URL = 'https://find.mr-beam.org/onlinecheck'

def __init__(self, plugin, analytics_handler, analytics_lock):
self._logger = mrb_logger("octoprint.plugins.mrbeam.analytics.timerhandler")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self._analytics_handler = analytics_handler
self._analytics_lock = analytics_lock
Expand Down
6 changes: 3 additions & 3 deletions octoprint_mrbeam/analytics/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FileUploader:
STATUS_DONE = 'done'

def __init__(self, plugin, directory, file, upload_type, lock):
self._logger = mrb_logger("octoprint.plugins.mrbeam.analytics.uploader")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self.directory = directory
self.file = file
Expand Down Expand Up @@ -199,7 +199,7 @@ def upload_now(plugin, analytics_lock):
AnalyticsFileUploader._instance._start_uploader_thread()
return
except Exception as e:
mrb_logger("octoprint.plugins.mrbeam.analytics.uploader").exception(
mrb_logger(__name__).exception(
'Exception during upload_now in AnalyticsFileUploader: {}'.format(e))


Expand Down Expand Up @@ -227,5 +227,5 @@ def upload_now(plugin, review_lock):
ReviewFileUploader._instance._start_uploader_thread()
return
except Exception as e:
mrb_logger("octoprint.plugins.mrbeam.analytics.uploader").exception(
mrb_logger(__name__).exception(
'Exception during upload_now in ReviewFileUploader: {}'.format(e))
2 changes: 1 addition & 1 deletion octoprint_mrbeam/analytics/usage_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UsageHandler(object):
MIN_DUST_VALUE = 0.2

def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.analytics.usage")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self._event_bus = plugin._event_bus
self._settings = plugin._settings
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/analytics/value_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ValueCollector(object):
def __init__(self, name):
self.name = name
self.valueList = list()
# self._logger = mrb_logger("octoprint.plugins.mrbeam.analyticshandler")
# self._logger = mrb_logger(__name__)

def addValue(self, value):
self.valueList.append(value)
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PICAMERA_AVAILABLE = True
except ImportError as e:
PICAMERA_AVAILABLE = False
logging.getLogger("octoprint.plugins.mrbeam.util.camera").error(
logging.getLogger(__name__).error(
"Could not import module 'mrbcamera'. Disabling camera integration. (%s: %s)", e.__class__.__name__, e)


Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/camera/label_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LabelPrinter(object):

def __init__(self, plugin, use_dummy_values=False):
self._plugin = plugin
self._logger = mrb_logger("octoprint.plugins.mrbeam.camera.label_printer")
self._logger = mrb_logger(__name__)
self._device_info = deviceInfo(use_dummy_values=use_dummy_values)

def print_label(self, request):
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/camera/mrbcamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, worker, stopEvent=None, shutter_speed=None, *args, **kwargs):
# self.exposure_mode = ''
self.stopEvent = stopEvent or threading.Event() # creates an unset event if not given
self.start_preview()
self._logger = mrb_logger("octoprint.plugins.mrbeam.util.camera.mrbcamera", lvl=logging.INFO)
self._logger = mrb_logger(__name__, lvl=logging.INFO)
self.busy = threading.Event()
self.worker = worker
self.captureLoop = LoopThread(
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# this is for the command line interface we're providing
def get_cli_commands(cli_group, pass_octoprint_ctx, *args, **kwargs):

_logger = mrb_logger("octoprint.plugins.mrbeam.cli")
_logger = mrb_logger(__name__)

# # > octoprint plugins mrbeam:debug_event MrBeamDebugEvent -p 42
# # remember to activate venv where MrBeamPlugin is installed in
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/gcodegenerator/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Converter():
_tempfile = "/tmp/_converter_output.tmp"

def __init__(self, params, model_path, workingAreaWidth = None, workingAreaHeight = None, min_required_disk_space=0):
self._log = mrb_logger("octoprint.plugins.mrbeam.converter")
self._log = mrb_logger(__name__)
self.workingAreaWidth = workingAreaWidth
self.workingAreaHeight = workingAreaHeight
self.optimize_path_order = True
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/gcodegenerator/img2gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__( self,
eng_compressor = 100, # DreamCut.
material = None):

self.log = mrb_logger("octoprint.plugins.mrbeam.img2gcode")
self.log = mrb_logger(__name__)
self.profiler = Profiler("img2gcode")
self.profiler.start('init')

Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/gcodegenerator/img_separator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ImageSeparator():
MAX_OUTER_CONTOURS = 30

def __init__( self):
self.log = mrb_logger("octoprint.plugins.mrbeam.img_separator")
self.log = mrb_logger(__name__)
self.img_debug_folder = "/tmp/separate_contours"

files = glob.glob(self.img_debug_folder+'/*')
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/gcodegenerator/jobtimeestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, plugin):
self._plugin = plugin
self._event_bus = plugin._event_bus
self._settings = plugin._settings
self._logger = mrb_logger("octoprint.plugins.mrbeam.job_time_estimation")
self._logger = mrb_logger(__name__)

self._last_estimation = -1
self._meta = dict()
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/compressor_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CompressorHandler(object):
MAX_TIMES_RPM_0 = 5

def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.compressorhandler")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self._event_bus = plugin._event_bus
self._printer = plugin._printer
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/dust_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DustManager(object):

def __init__(self, plugin):
self._plugin = plugin
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.dustmanager")
self._logger = mrb_logger(__name__)
self.dev_mode = plugin._settings.get_boolean(['dev', 'iobeam_disable_warnings'])
self._event_bus = plugin._event_bus
self._printer = plugin._printer
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/hw_malfunction_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HwMalfunctionHandler(object):
MALFUNCTION_ID_GENERAL = 'hw_malfunction'

def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.hw_malfunction")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self._user_notification_system = plugin.user_notification_system
self._event_bus = plugin._event_bus
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/interlock_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, plugin, event_bus, plugin_manager):
self._plugin = plugin
self._event_bus = event_bus
self._plugin_manager = plugin_manager
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.interlockhandler")
self._logger = mrb_logger(__name__)

self._event_bus.subscribe(MrBeamEvents.MRB_PLUGIN_INITIALIZED, self._on_mrbeam_plugin_initialized)

Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/iobeam_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __init__(self, plugin):
self._plugin = plugin
self._event_bus = plugin._event_bus
self._socket_file = plugin._settings.get(["dev", "sockets", "iobeam"])
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam")
self._logger = mrb_logger(__name__)

self._shutdown_signaled = False
self._isConnected = False
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/laserhead_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LaserheadHandler(object):
LASERHEAD_SERIAL_REGEXP = re.compile("^[0-9a-f-]{36}$")

def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.laserhead")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self._settings = plugin._settings
self._event_bus = plugin._event_bus
Expand Down
6 changes: 3 additions & 3 deletions octoprint_mrbeam/iobeam/lid_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, plugin):
self._printer = plugin._printer
self._plugin_manager = plugin._plugin_manager
self._laserCutterProfile = plugin.laserCutterProfileManager.get_current_or_default()
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.lidhandler",
self._logger = mrb_logger(__name__,
logging.INFO)
self._lid_closed = True
self._interlock_closed = True
Expand Down Expand Up @@ -426,9 +426,9 @@ def __init__(self, _plugin, _plugin_manager, path, debug=False):
self.analytics = None

if debug:
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.lidhandler.PhotoCreator", logging.DEBUG)
self._logger = mrb_logger(__name__, logging.DEBUG)
else:
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.lidhandler.PhotoCreator", logging.INFO)
self._logger = mrb_logger(__name__, logging.INFO)

self.last_markers, self.last_shutter_speed = self.load_camera_settings()
if self._settings.get(["cam", "keepOriginals"]):
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/onebutton_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, plugin, event_bus, plugin_manager, file_manager, settings, pr
self._settings = settings
self._printer = printer
self._user_notification_system = plugin.user_notification_system
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.onebutton_handler")
self._logger = mrb_logger(__name__)
self._event_bus.subscribe(MrBeamEvents.MRB_PLUGIN_INITIALIZED, self._on_mrbeam_plugin_initialized)

self.ready_to_laser_ts = -1
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/iobeam/temperature_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TemperatureManager(object):
TEMP_MAX_AGE = 10 # seconds

def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.iobeam.temperaturemanager")
self._logger = mrb_logger(__name__)
self._plugin = plugin
self._event_bus = plugin._event_bus
self.temperature = None
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/led_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, plugin):
CommandTrigger.__init__(self, plugin._printer)
self._plugin = plugin
self._event_bus = plugin._event_bus
self._logger = mrb_logger("octoprint.plugins.mrbeam.led_events")
self._logger = mrb_logger(__name__)

self._watch_thread = None
self._watch_active = False
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Materials(object):


def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.materials")
self._logger = mrb_logger(__name__)
self.plugin = plugin
self.custom_materials_file = os.path.join(self.plugin._settings.getBaseFolder('base'), self.FILE_CUSTOM_MATERIALS)

Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Migration(object):


def __init__(self, plugin):
self._logger = mrb_logger("octoprint.plugins.mrbeam.migrate")
self._logger = mrb_logger(__name__)
self.plugin = plugin

self.version_previous = self.plugin._settings.get(['version']) or "0.0.0"
Expand Down
Loading