|
18 | 18 | import numpy as np
|
19 | 19 | import pandas as pd
|
20 | 20 |
|
| 21 | +# Configuration of logging messages |
| 22 | +LOGGER_NSEPARATORS = 50 |
| 23 | +LOGGER_SEPARATOR = "-" |
| 24 | +LOGGER_NSEPARATORS_CONTEXTUAL = 3 |
| 25 | +LOGGER_SEPARATOR_CONTEXTUAL = "#" |
| 26 | + |
21 | 27 |
|
22 | 28 | def script_template(filename, comment,
|
23 | 29 | type="simple",
|
@@ -119,25 +125,44 @@ class StartedCompletedLogger(logging.Logger):
|
119 | 125 | """ Add context to logging messages via the context attribute """
|
120 | 126 |
|
121 | 127 | def __init__(self, *args, **kwargs):
|
122 |
| - self.context = "" |
123 | 128 | super(StartedCompletedLogger, self).__init__(*args, **kwargs)
|
124 | 129 |
|
125 | 130 | def started(self):
|
126 | 131 | self.info("@@@ Process started @@@")
|
| 132 | + self.info(LOGGER_SEPARATOR*LOGGER_NSEPARATORS) |
| 133 | + self.info("") |
127 | 134 |
|
128 | 135 | def completed(self):
|
129 |
| - self.context = "" |
130 | 136 | self.info("")
|
| 137 | + self.info(LOGGER_SEPARATOR*LOGGER_NSEPARATORS) |
131 | 138 | self.info("@@@ Process completed @@@")
|
132 | 139 |
|
133 | 140 |
|
134 | 141 | class HydrodiyContextualLogger(StartedCompletedLogger):
|
135 | 142 | """ Add context to logging messages via the context attribute """
|
136 | 143 |
|
137 | 144 | def __init__(self, *args, **kwargs):
|
138 |
| - self.context = "" |
| 145 | + self._context = "" |
139 | 146 | super(HydrodiyContextualLogger, self).__init__(*args, **kwargs)
|
140 | 147 |
|
| 148 | + @property |
| 149 | + def context(self): |
| 150 | + return self._context |
| 151 | + |
| 152 | + @context.setter |
| 153 | + def context(self, value): |
| 154 | + self._context = str(value) |
| 155 | + if self._context != "": |
| 156 | + self.info(LOGGER_SEPARATOR*LOGGER_NSEPARATORS) |
| 157 | + sep = LOGGER_SEPARATOR_CONTEXTUAL\ |
| 158 | + *LOGGER_NSEPARATORS_CONTEXTUAL |
| 159 | + mess = sep+" "+self._context+" "+sep |
| 160 | + self.info(mess) |
| 161 | + |
| 162 | + def completed(self): |
| 163 | + self.context = "" |
| 164 | + super(HydrodiyContextualLogger, self).completed() |
| 165 | + |
141 | 166 | def _log(self, level, msg, args, exc_info=None, extra=None):
|
142 | 167 | if self.context != "":
|
143 | 168 | msg = "{{ {0} }} {1}".format(self.context, msg)
|
|
0 commit comments