ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since 38beeab was
38beeab,
checked in by Ricardo Ferraz Leal <ricleal@…>, 7 years ago
|
Logger is now a separate file
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | from __future__ import print_function |
---|
2 | |
---|
3 | ''' |
---|
4 | Module that manages the global logging |
---|
5 | ''' |
---|
6 | |
---|
7 | import logging |
---|
8 | import logging.config |
---|
9 | import os |
---|
10 | import os.path |
---|
11 | |
---|
12 | class SetupLogger(object): |
---|
13 | ''' |
---|
14 | Called at the beginning of run.py or sasview.py |
---|
15 | ''' |
---|
16 | |
---|
17 | def __init__(self, logger_name): |
---|
18 | self.config_file = os.path.join(os.path.abspath( |
---|
19 | os.path.dirname(__file__)), 'logging.ini') |
---|
20 | self.name = logger_name |
---|
21 | |
---|
22 | def config_production(self): |
---|
23 | ''' |
---|
24 | ''' |
---|
25 | logger = logging.getLogger(self.name) |
---|
26 | if not logger.root.handlers: |
---|
27 | self._read_config_file() |
---|
28 | logging.captureWarnings(True) |
---|
29 | logger = logging.getLogger(self.name) |
---|
30 | return logger |
---|
31 | |
---|
32 | def config_development(self): |
---|
33 | ''' |
---|
34 | ''' |
---|
35 | self._read_config_file() |
---|
36 | logger = logging.getLogger(self.name) |
---|
37 | self._update_all_logs_to_debug(logger) |
---|
38 | logging.captureWarnings(True) |
---|
39 | return logger |
---|
40 | |
---|
41 | def _read_config_file(self): |
---|
42 | ''' |
---|
43 | ''' |
---|
44 | logging.config.fileConfig(self.config_file) |
---|
45 | |
---|
46 | def _update_all_logs_to_debug(self, logger): |
---|
47 | ''' |
---|
48 | This updates all loggers and respective handlers to DEBUG |
---|
49 | ''' |
---|
50 | for handler in logger.handlers or logger.parent.handlers: |
---|
51 | handler.setLevel(logging.DEBUG) |
---|
52 | for name, _ in logging.Logger.manager.loggerDict.items(): |
---|
53 | logging.getLogger(name).setLevel(logging.DEBUG) |
---|
Note: See
TracBrowser
for help on using the repository browser.