Skip to content

Commit ea1b10f

Browse files
committed
fix logging
bump version to 1.0.17
1 parent 12871eb commit ea1b10f

2 files changed

Lines changed: 31 additions & 28 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "htmlcmp"
3-
version = "1.0.16"
3+
version = "1.0.17"
44
description = "Compare HTML files by rendered output"
55
classifiers = []
66
authors = [

src/htmlcmp/compare_output_server.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from htmlcmp.html_render_diff import get_browser, html_render_diff
1818

1919

20+
logger = logging.getLogger(__name__)
21+
22+
2023
class Config:
2124
path_a: Path = None
2225
path_b: Path = None
@@ -37,31 +40,31 @@ def dispatch(self, event):
3740
event_type = event.event_type
3841
src_path = Path(event.src_path)
3942

40-
logging.verbose(f"Watchdog event: {event_type} {src_path}")
43+
logger.verbose(f"Watchdog event: {event_type} {src_path}")
4144

4245
if event_type not in ["moved", "deleted", "created", "modified"]:
4346
return
4447

4548
if src_path.is_file():
46-
logging.debug(
49+
logger.debug(
4750
f"Submit watchdog file change: {event_type} {src_path}"
4851
)
4952
Config.comparator.submit(src_path.relative_to(self._path))
5053

51-
logging.info("Create watchdog for paths:")
52-
logging.info(f" A: {Config.path_a}")
53-
logging.info(f" B: {Config.path_b}")
54+
logger.info("Create watchdog for paths:")
55+
logger.info(f" A: {Config.path_a}")
56+
logger.info(f" B: {Config.path_b}")
5457

5558
self._observer = watchdog.observers.Observer()
5659
self._observer.schedule(Handler(Config.path_a), Config.path_a, recursive=True)
5760
self._observer.schedule(Handler(Config.path_b), Config.path_b, recursive=True)
5861

5962
def start(self):
60-
logging.info("Starting watchdog observer")
63+
logger.info("Starting watchdog observer")
6164
self._observer.start()
6265

6366
def init_compare(a: Path, b: Path):
64-
logging.verbose(f"Initial compare: {a} vs {b}")
67+
logger.verbose(f"Initial compare: {a} vs {b}")
6568

6669
if not isinstance(a, Path) or not isinstance(b, Path):
6770
raise TypeError("Paths must be of type Path")
@@ -77,23 +80,23 @@ def init_compare(a: Path, b: Path):
7780

7881
for name in common:
7982
if (a / name).is_file() and comparable_file(a / name):
80-
logging.debug(
83+
logger.debug(
8184
f"Submit initial file comparison: {common_path / name}"
8285
)
8386
Config.comparator.submit(common_path / name)
8487
elif (a / name).is_dir():
8588
init_compare(a / name, b / name)
8689

87-
logging.info("Kick off initial comparison of all files")
90+
logger.info("Kick off initial comparison of all files")
8891
init_compare(Config.path_a, Config.path_b)
89-
logging.info("Initial comparison submitted")
92+
logger.info("Initial comparison submitted")
9093

9194
def stop(self):
92-
logging.info("Stopping watchdog observer")
95+
logger.info("Stopping watchdog observer")
9396
self._observer.stop()
9497

9598
def join(self):
96-
logging.info("Joining watchdog observer")
99+
logger.info("Joining watchdog observer")
97100
self._observer.join()
98101

99102

@@ -105,7 +108,7 @@ def initializer():
105108
browser = get_browser(driver=Config.driver)
106109
Config.thread_local.browser = browser
107110

108-
logging.info(f"Creating comparator with {max_workers} workers")
111+
logger.info(f"Creating comparator with {max_workers} workers")
109112

110113
self._executor = ThreadPoolExecutor(
111114
max_workers=max_workers, initializer=initializer
@@ -114,7 +117,7 @@ def initializer():
114117
self._future = {}
115118

116119
def submit(self, path: Path):
117-
logging.debug(f"Submitting comparison for path: {path}")
120+
logger.debug(f"Submitting comparison for path: {path}")
118121

119122
if not isinstance(path, Path):
120123
raise TypeError("Path must be of type Path")
@@ -131,7 +134,7 @@ def submit(self, path: Path):
131134
self._future[path] = self._executor.submit(self.compare, path)
132135

133136
def compare(self, path: Path):
134-
logging.debug(f"Comparing files for path: {path}")
137+
logger.debug(f"Comparing files for path: {path}")
135138

136139
if not isinstance(path, Path):
137140
raise TypeError("Path must be of type Path")
@@ -148,7 +151,7 @@ def compare(self, path: Path):
148151
self._future.pop(path)
149152

150153
def result(self, path: Path):
151-
logging.debug(f"Getting comparison result for path: {path}")
154+
logger.debug(f"Getting comparison result for path: {path}")
152155

153156
if not isinstance(path, Path):
154157
raise TypeError("Path must be of type Path")
@@ -158,7 +161,7 @@ def result(self, path: Path):
158161
return "unknown"
159162

160163
def result_symbol(self, path: Path):
161-
logging.debug(f"Getting comparison result symbol for path: {path}")
164+
logger.debug(f"Getting comparison result symbol for path: {path}")
162165

163166
if not isinstance(path, Path):
164167
raise TypeError("Path must be of type Path")
@@ -173,7 +176,7 @@ def result_symbol(self, path: Path):
173176
return "⛔"
174177

175178
def result_css(self, path: Path):
176-
logging.debug(f"Getting comparison result CSS for path: {path}")
179+
logger.debug(f"Getting comparison result CSS for path: {path}")
177180

178181
if not isinstance(path, Path):
179182
raise TypeError("Path must be of type Path")
@@ -193,7 +196,7 @@ def result_css(self, path: Path):
193196

194197
@app.route("/")
195198
def root():
196-
logging.debug("Generating root directory listing")
199+
logger.debug("Generating root directory listing")
197200

198201
def print_tree(a: Path, b: Path):
199202
if not isinstance(a, Path) or not isinstance(b, Path):
@@ -274,7 +277,7 @@ def print_tree(a: Path, b: Path):
274277

275278
@app.route("/compare/<path:path>")
276279
def compare(path: str):
277-
logging.debug(f"Generating comparison page for path: {path}")
280+
logger.debug(f"Generating comparison page for path: {path}")
278281

279282
if not isinstance(path, str):
280283
raise TypeError("Path must be a string")
@@ -316,7 +319,7 @@ def compare(path: str):
316319

317320
@app.route("/image_diff/<path:path>")
318321
def image_diff(path: str):
319-
logging.debug(f"Generating image diff for path: {path}")
322+
logger.debug(f"Generating image diff for path: {path}")
320323

321324
if not isinstance(path, str):
322325
raise TypeError("Path must be a string")
@@ -334,7 +337,7 @@ def image_diff(path: str):
334337

335338
@app.route("/file/<variant>/<path:path>")
336339
def file(variant: str, path: str):
337-
logging.debug(f"Serving file for variant: {variant}, path: {path}")
340+
logger.debug(f"Serving file for variant: {variant}, path: {path}")
338341

339342
if not isinstance(variant, str) or not isinstance(path, str):
340343
raise TypeError("Variant and path must be strings")
@@ -355,18 +358,18 @@ def setup_logging(verbosity: int):
355358
else:
356359
level = logging.WARNING
357360

358-
logger = logging.getLogger()
359-
logger.setLevel(level)
360-
logger.handlers.clear()
361-
362361
formatter = logging.Formatter(
363362
fmt="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
364363
datefmt="%Y-%m-%d %H:%M:%S",
365364
)
366365

367366
console_handler = logging.StreamHandler(sys.stderr)
368367
console_handler.setFormatter(formatter)
369-
logger.addHandler(console_handler)
368+
369+
root_logger = logging.getLogger()
370+
root_logger.setLevel(level)
371+
root_logger.handlers.clear()
372+
root_logger.addHandler(console_handler)
370373

371374

372375
def main():

0 commit comments

Comments
 (0)