MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / initialize_logging

Method initialize_logging

mssqlcli/mssql_cli.py:234–272  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

232 # return [(None, None, None, message, '', True)]
233
234 def initialize_logging(self):
235 log_file = self.config['main']['log_file']
236 if log_file == 'default':
237 log_file = config_location() + 'mssqlcli.log'
238 ensure_dir_exists(log_file)
239 log_level = self.config['main']['log_level']
240
241 # Disable logging if value is NONE by switching to a no-op handler.
242 # Set log level to a high value so it doesn't even waste cycles getting
243 # called.
244 if log_level.upper() == 'NONE':
245 handler = logging.NullHandler()
246 else:
247 # creates a log buffer with max size of 20 MB and 5 backup files
248 handler = RotatingFileHandler(os.path.expanduser(log_file), encoding='utf-8',
249 maxBytes=1024*1024*20, backupCount=5)
250
251 level_map = {'CRITICAL': logging.CRITICAL,
252 'ERROR': logging.ERROR,
253 'WARNING': logging.WARNING,
254 'INFO': logging.INFO,
255 'DEBUG': logging.DEBUG,
256 'NONE': logging.CRITICAL
257 }
258
259 log_level = level_map[log_level.upper()]
260
261 formatter = logging.Formatter(
262 '%(asctime)s (%(process)d/%(threadName)s) '
263 '%(name)s %(levelname)s - %(message)s')
264
265 handler.setFormatter(formatter)
266
267 root_logger = logging.getLogger('mssqlcli')
268 root_logger.addHandler(handler)
269 root_logger.setLevel(log_level)
270
271 root_logger.info('Initializing mssqlcli logging.')
272 root_logger.debug('Log file %r.', log_file)
273
274 def set_main_mssqlcli_client(self, mssqlcli_client):
275 self.mssqlcliclient_main = mssqlcli_client

Callers 1

__init__Method · 0.95

Calls 2

config_locationFunction · 0.90
ensure_dir_existsFunction · 0.90

Tested by

no test coverage detected