From 47a6eaa93632015276a02f09b5558a3840c514d9 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 21 Nov 2014 17:56:57 +0100 Subject: [PATCH] use logging for exceptions in webserver, check BAM_VERBOSE env var --- client/cli/bam.py | 5 ++++- tests/blendfile_templates.py | 1 + tests/test_cli.py | 7 ++++++- webservice/bam/application/__init__.py | 17 ++++++++++++----- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/client/cli/bam.py b/client/cli/bam.py index f36c5f7..f4e10be 100755 --- a/client/cli/bam.py +++ b/client/cli/bam.py @@ -35,7 +35,10 @@ del os, sys, path import logging log = logging.getLogger("bam_cli") -logging.basicConfig(level=logging.DEBUG) + +# if we're a module, don't mess with logging level +if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG) def fatal(msg): diff --git a/tests/blendfile_templates.py b/tests/blendfile_templates.py index 45f355e..95e87c4 100644 --- a/tests/blendfile_templates.py +++ b/tests/blendfile_templates.py @@ -58,6 +58,7 @@ def create_from_files(deps): f_rel = bpy.path.relpath(f_abs) image = bpy.data.images.load(f) image.use_fake_user = True + deps.append(f_abs) if __name__ == "__main__": diff --git a/tests/test_cli.py b/tests/test_cli.py index 9980543..89180bb 100755 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -13,7 +13,12 @@ Run a single test: python3 -m unittest test_cli.BamCommitTest.test_checkout """ -VERBOSE = 1 +import os +VERBOSE = os.environ.get("VERBOSE", False) +if VERBOSE: + # for the server subprocess + os.environ["BAM_VERBOSE"] = "1" + # ------------------ # Ensure module path diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index bc01f0f..50f7f0d 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -17,6 +17,12 @@ # # ***** END GPL LICENCE BLOCK ***** +""" +Environment vars: +- BAM_VERBOSE, set to get debug logging. +""" + + # ------------------ # Ensure module path import os @@ -62,7 +68,9 @@ from application.modules.projects import admin from application.modules.projects.model import Project, ProjectSetting log = logging.getLogger("webservice") -logging.basicConfig(level=logging.DEBUG) + +if os.environ.get("BAM_VERBOSE"): + logging.basicConfig(level=logging.DEBUG) @auth.get_password @@ -340,8 +348,8 @@ class FileAPI(Resource): import blendfile_pack assert(os.path.exists(filepath) and not os.path.isdir(filepath)) - print(" Source path:", filepath) - print(" Zip path:", filepath_zip) + log.info(" Source path: %r" % filepath) + log.info(" Zip path: %r" % filepath_zip) deps_remap = {} paths_remap = {} @@ -356,8 +364,7 @@ class FileAPI(Resource): deps_remap=deps_remap, paths_remap=paths_remap, paths_uuid=paths_uuid, report=report) except: - import traceback - traceback.print_exc() + log.exception("Error packing the blend file") return else: # non blend-file