MCPcopy Index your code
hub / github.com/dbcli/pgcli / initialize_logging

Method initialize_logging

pgcli/main.py:563–601  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

561 return [(None, None, None, message, "", True, True)]
562
563 def initialize_logging(self):
564 log_file = self.config["main"]["log_file"]
565 if log_file == "default":
566 log_file = config_location() + "log"
567 ensure_dir_exists(log_file)
568 log_level = self.config["main"]["log_level"]
569
570 # Disable logging if value is NONE by switching to a no-op handler.
571 # Set log level to a high value so it doesn't even waste cycles getting called.
572 if log_level.upper() == "NONE":
573 handler = logging.NullHandler()
574 else:
575 handler = logging.FileHandler(os.path.expanduser(log_file))
576
577 level_map = {
578 "CRITICAL": logging.CRITICAL,
579 "ERROR": logging.ERROR,
580 "WARNING": logging.WARNING,
581 "INFO": logging.INFO,
582 "DEBUG": logging.DEBUG,
583 "NONE": logging.CRITICAL,
584 }
585
586 log_level = level_map[log_level.upper()]
587
588 formatter = logging.Formatter("%(asctime)s (%(process)d/%(threadName)s) %(name)s %(levelname)s - %(message)s")
589
590 handler.setFormatter(formatter)
591
592 root_logger = logging.getLogger("pgcli")
593 root_logger.addHandler(handler)
594 root_logger.setLevel(log_level)
595
596 root_logger.debug("Initializing pgcli logging.")
597 root_logger.debug("Log file %r.", log_file)
598
599 pgspecial_logger = logging.getLogger("pgspecial")
600 pgspecial_logger.addHandler(handler)
601 pgspecial_logger.setLevel(log_level)
602
603 def connect_dsn(self, dsn, **kwargs):
604 self.connect(dsn=dsn, **kwargs)

Callers 1

__init__Method · 0.95

Calls 2

config_locationFunction · 0.85
ensure_dir_existsFunction · 0.85

Tested by

no test coverage detected