Fix logging

This commit is contained in:
James Campbell 2024-06-07 03:11:07 -04:00
parent 4afa78713f
commit 7bad418850
Signed by: james
GPG Key ID: 2287C33A40DC906A

View File

@ -86,6 +86,7 @@ def init_logging(config):
else: else:
old_file_logger = None old_file_logger = None
if config.log_file is not None:
# Create and add the handler if it doesn't exist # Create and add the handler if it doesn't exist
if file_log_handler is None: if file_log_handler is None:
file_log_handler = logging.FileHandler(config.log_file, encoding='utf-8') file_log_handler = logging.FileHandler(config.log_file, encoding='utf-8')
@ -104,7 +105,7 @@ def init_logging(config):
logger.removeHandler(old_file_logger) logger.removeHandler(old_file_logger)
# Note where logs are being written # Note where logs are being written
print("Logging to {} ({})".format(config.log_file, config.file_log_level)) #print("Logging to {} ({})".format(config.log_file, config.file_log_level))
else: else:
if file_log_handler is not None: if file_log_handler is not None:
logger.removeHandler(file_log_handler) logger.removeHandler(file_log_handler)
@ -214,7 +215,7 @@ class Config:
self.stderr_log_level = 'INFO' # Log level for stderr logging (or 'off') self.stderr_log_level = 'INFO' # Log level for stderr logging (or 'off')
self.file_log_level = 'INFO' # Log level for file logging (od 'off') self.file_log_level = 'INFO' # Log level for file logging (od 'off')
self.log_file = 'pgmon.log' # Log file self.log_file = None # Log file
self.metrics = {} # Metrics self.metrics = {} # Metrics
self.clusters = {} # Known clusters self.clusters = {} # Known clusters
@ -1088,7 +1089,7 @@ class Server:
try: try:
self.reload_config() self.reload_config()
except Exception as e: except Exception as e:
logger.ERROR("Reload failed: {}".format(e)) logger.error("Reload failed: {}".format(e))
# If we just timed out waiting for a request, go back to waiting # If we just timed out waiting for a request, go back to waiting
if conn is None: if conn is None:
@ -1249,9 +1250,10 @@ class Worker(threading.Thread):
continue continue
# Set the result on the request # Set the result on the request
if metric.type == 'value':
if len(res) == 0: if len(res) == 0:
req.set_result("Empty result set") req.set_result("Empty result set")
elif metric.type == 'value': else:
req.set_result("{}".format(list(res[0].values())[0])) req.set_result("{}".format(list(res[0].values())[0]))
elif metric.type == 'row': elif metric.type == 'row':
req.set_result(json.dumps(res[0])) req.set_result(json.dumps(res[0]))