From 2d21ea059b8e1cf74a09bef2344105a43a00dbfd Mon Sep 17 00:00:00 2001 From: Dave Page Date: Tue, 16 Dec 2014 15:54:29 +0000 Subject: [PATCH] Add a basic logging system. --- web/config.py | 34 ++++++++++++++++++++++++++++++++++ web/pgAdmin4.py | 33 +++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 web/config.py diff --git a/web/config.py b/web/config.py new file mode 100644 index 000000000..f443a4ba1 --- /dev/null +++ b/web/config.py @@ -0,0 +1,34 @@ +########################################################################## +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2014, The pgAdmin Development Team +# This software is released under the PostgreSQL Licence +# +# config.py - Core application configuration settings +# +########################################################################## + +from logging import * + +# Application log level - one of: +# CRITICAL 50 +# ERROR 40 +# WARNING 30 +# SQL 25 +# INFO 20 +# DEBUG 10 +# NOTSET 0 +PGADMIN_LOG_LEVEL = DEBUG + +# Log file name +PGADMIN_LOG_FILE = 'pgadmin4.log' + +# Log format. See +PGADMIN_LOG_FORMAT='%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' + +# Load local config overrides +try: + from config_local import * +except ImportError: + pass diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 0e673f3a5..8d65b8044 100755 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -1,9 +1,35 @@ -import os, sys, inspect -from time import time,ctime -from flask import Flask +########################################################################## +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2014, The pgAdmin Development Team +# This software is released under the PostgreSQL Licence +# +# pgAdmin4.py - Main application entry point +# +########################################################################## +import os, sys, inspect +from time import time, ctime +from flask import Flask +import logging + +# We need to include the root directory in sys.path to ensure that we can +# find everything we need when running in the standalone runtime. +sys.path.append(os.path.dirname(__file__)) + +# Configuration settings +from config import * + +# Setup the app object app = Flask(__name__) +# Setup logging and log the application startup +logging.addLevelName(25, 'SQL') +logging.basicConfig(filename=PGADMIN_LOG_FILE, format=PGADMIN_LOG_FORMAT, level=logging.DEBUG) +app.logger.setLevel(PGADMIN_LOG_LEVEL) +app.logger.debug('Starting pgAdmin 4...') + # The main index page @app.route("/") def index(): @@ -17,7 +43,6 @@ Today is %s return output - # A special URL used to "ping" the server @app.route("/ping") def ping():