Skip to content

Commit 0c8f26c

Browse files
committed
package.py - Fixed and improved logging
1 parent 778ceff commit 0c8f26c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

package.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def generate_content_hash(source_paths,
216216
for source_path in source_paths:
217217
if os.path.isdir(source_path):
218218
source_dir = source_path
219-
for source_file in list_files(source_dir, logger=logger):
219+
_logger = logger if logger.isEnabledFor(DEBUG3) else None
220+
for source_file in list_files(source_dir, logger=_logger):
220221
update_hash(hash_obj, source_dir, source_file)
221222
if logger:
222223
logger.debug(os.path.join(source_dir, source_file))
@@ -488,8 +489,9 @@ def str_int_to_timestamp(s):
488489
class BuildPlanManager:
489490
""""""
490491

491-
def __init__(self):
492+
def __init__(self, logger=None):
492493
self._source_paths = None
494+
self._logger = logger or logging.root
493495

494496
def hash(self, extra_paths):
495497
if not self._source_paths:
@@ -500,8 +502,9 @@ def hash(self, extra_paths):
500502
# Generate a hash based on file names and content. Also use the
501503
# runtime value, build command, and content of the build paths
502504
# because they can have an effect on the resulting archive.
503-
logger.debug("Computing content hash on files...")
504-
content_hash = generate_content_hash(content_hash_paths, logger=logger)
505+
self._logger.debug("Computing content hash on files...")
506+
content_hash = generate_content_hash(content_hash_paths,
507+
logger=self._logger)
505508
return content_hash
506509

507510
def plan(self, source_path, query):
@@ -708,7 +711,7 @@ def prepare_command(args):
708711
recreate_missing_package = yesno_bool(args.recreate_missing_package)
709712
docker = query.docker
710713

711-
bpm = BuildPlanManager()
714+
bpm = BuildPlanManager(logger=logger)
712715
build_plan = bpm.plan(source_path, query)
713716

714717
# Expand a Terraform path.<cwd|root|module> references
@@ -799,7 +802,7 @@ def build_command(args):
799802
# Zip up the build plan and write it to the target filename.
800803
# This will be used by the Lambda function as the source code package.
801804
with ZipWriteStream(filename) as zs:
802-
bpm = BuildPlanManager()
805+
bpm = BuildPlanManager(logger=logger)
803806
bpm.execute(build_plan, zs, query)
804807

805808
os.utime(filename, ns=(timestamp, timestamp))

0 commit comments

Comments
 (0)