Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion samtranslator/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from samtranslator.validator.validator import SamTemplateValidator
from samtranslator.model import ResourceTypeResolver, sam_resources
from samtranslator.plugins import LifeCycleEvents
import logging
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the root logger, which will log in any one using SAM to translate without a way to turn it off.

logging should be done by adding a __name__.

logger = logging.getLogger(__name__) and then log by doing logger.warning("Logging a Warning")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you send a PR? How do other consumers then turn that off?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://stackoverflow.com/a/35325280

Should magically work. You can also manipulate the libraries logger too. For example, SAM CLI could then turn the SAM Translators logging on for a given level if they so wanted to.

Copy link

@fatbasstard fatbasstard Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


class Parser:
def __init__(self):
Expand All @@ -25,4 +26,11 @@ def _validate(self, sam_template, parameter_values):
raise InvalidDocumentException(
[InvalidTemplateException("'Resources' section is required")])

SamTemplateValidator.validate(sam_template)
validation_errors = SamTemplateValidator.validate(sam_template)
has_errors = len(validation_errors)

if has_errors:
# NOTE: eventually we will throw on invalid schema
# raise InvalidDocumentException([InvalidTemplateException(validation_errors)])
logging.warning(
"JSON_VALIDATION_WARNING: {0}".format(validation_errors))