summaryrefslogtreecommitdiff
path: root/grc/main.py
diff options
context:
space:
mode:
authorSeth Hitefield <sdhitefield@gmail.com>2016-09-22 14:58:31 -0400
committerSeth Hitefield <sdhitefield@gmail.com>2016-09-23 16:18:10 -0400
commitba675b38ad095dba6fa15af04b158ca04667fa8b (patch)
treec2b4ddafa123ebda79087c342105caf11754d8cf /grc/main.py
parentc7ea78c37db2d36ace3051ce10bc94fe71501819 (diff)
grc: refactor: Added logging
Diffstat (limited to 'grc/main.py')
-rwxr-xr-xgrc/main.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/grc/main.py b/grc/main.py
index e0f2b26d05..305e8b8f78 100755
--- a/grc/main.py
+++ b/grc/main.py
@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-import argparse, sys
+import argparse, logging, sys
import gi
gi.require_version('Gtk', '3.0')
@@ -35,11 +35,20 @@ GRC comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it.
"""
+LOG_LEVELS = {
+ 'debug': logging.DEBUG,
+ 'info': logging.INFO,
+ 'warning': logging.WARNING,
+ 'error': logging.ERROR,
+ 'critical': logging.CRITICAL,
+}
+
def main():
parser = argparse.ArgumentParser(
description=VERSION_AND_DISCLAIMER_TEMPLATE % gr.version())
parser.add_argument('flow_graphs', nargs='*')
+ parser.add_argument('--log', choices=['debug', 'info', 'warning', 'error', 'critical'], default='warning')
args = parser.parse_args()
try:
@@ -47,6 +56,25 @@ def main():
except:
pass
+ # Enable logging
+ # Note: All other modules need to use the 'grc.<module>' convention
+ log = logging.getLogger('grc')
+ log.setLevel(logging.DEBUG)
+
+ # Console formatting
+ console = logging.StreamHandler()
+ console.setLevel(LOG_LEVELS[args.log])
+
+ msg_format = '[%(asctime)s - %(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)'
+ date_format = '%I:%M'
+ formatter = logging.Formatter(msg_format, datefmt=date_format)
+
+ #formatter = utils.log.ConsoleFormatter()
+ console.setFormatter(formatter)
+ log.addHandler(console)
+
+ log.debug("Loading platform")
+
platform = Platform(
version=gr.version(),
version_parts=(gr.major_version(), gr.api_version(), gr.minor_version()),
@@ -54,5 +82,7 @@ def main():
install_prefix=gr.prefix()
)
+ log.debug("Loading application")
app = Application(args.flow_graphs, platform)
+ log.debug("Running")
sys.exit(app.run())