Fixing logging
Change-Id: I3bd5168110985fd06faa6a4bc2fe3d713a208337
diff --git a/src/tosca/generator.py b/src/tosca/generator.py
index 13472f9..3f54a77 100644
--- a/src/tosca/generator.py
+++ b/src/tosca/generator.py
@@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+from xosconfig import Config
+from multistructlog import create_logger
+log = create_logger(Config().get('logging'))
import os
from default import TOSCA_DEFS_DIR, TOSCA_KEYS_DIR
@@ -38,7 +41,7 @@
os.remove(keys_fn)
def generate(self, client):
- print "[XOS-TOSCA] Generating TOSCA"
+ log.info("[XOS-TOSCA] Generating TOSCA")
try:
xproto = client.utility.GetXproto(Empty())
@@ -48,10 +51,9 @@
args.target = os.path.join(current_dir, 'xtarget/tosca.xtarget')
args.write_to_file = 'target'
XOSProcessor.process(args)
- print "[XOS-TOSCA] Recipes generated in %s" % args.output
+ log.info("[XOS-TOSCA] Recipes generated in %s" % args.output)
except Exception as e:
- print "[XOS-TOSCA] Failed to generate TOSCA"
- print e
+ log.exception("[XOS-TOSCA] Failed to generate TOSCA")
try:
xproto = client.utility.GetXproto(Empty())
@@ -62,8 +64,7 @@
args.write_to_file = 'single'
args.dest_file = 'KEYS.py'
XOSProcessor.process(args)
- print "[XOS-TOSCA] TOSCA Keys generated in %s" % args.output
+ log.info("[XOS-TOSCA] TOSCA Keys generated in %s" % args.output)
except Exception as e:
- print "[XOS-TOSCA] Failed to generate TOSCA Keys"
- print e
+ log.exception("[XOS-TOSCA] Failed to generate TOSCA Keys")
diff --git a/src/tosca/parser.py b/src/tosca/parser.py
index b691166..fe8382b 100644
--- a/src/tosca/parser.py
+++ b/src/tosca/parser.py
@@ -14,6 +14,10 @@
# limitations under the License.
+from xosconfig import Config
+from multistructlog import create_logger
+log = create_logger(Config().get('logging'))
+
from toscaparser.tosca_template import ToscaTemplate, ValidationError
from default import TOSCA_RECIPES_DIR
from grpc_client.resources import RESOURCES
@@ -227,17 +231,16 @@
reference_only = True
if self.delete and not model.is_new and not reference_only:
- print "[XOS-Tosca] Deleting model %s[%s]" % (class_name, model.id)
+ log.info("[XOS-Tosca] Deleting model %s[%s]" % (class_name, model.id))
model.delete()
elif not self.delete:
- print "[XOS-Tosca] Saving model %s[%s]" % (class_name, model.id)
+ log.info("[XOS-Tosca] Saving model %s[%s]" % (class_name, model.id))
model.save()
self.saved_model_by_name[recipe.name] = model
except Exception, e:
- print "[XOS-TOSCA] Failed to save model: %s [%s]" % (class_name, recipe.name)
- traceback.print_exc()
+ log.exception("[XOS-TOSCA] Failed to save model: %s [%s]" % (class_name, recipe.name))
raise e
except ValidationError as e:
@@ -257,7 +260,7 @@
exception_msg = e._state.details
raise Exception(exception_msg)
except Exception, e:
- print e
+ log.exception(e)
raise Exception(e)