Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

logging module instead of prints #178

Open
dirkgomez opened this issue Jul 26, 2021 · 1 comment
Open

logging module instead of prints #178

dirkgomez opened this issue Jul 26, 2021 · 1 comment

Comments

@dirkgomez
Copy link

dirkgomez commented Jul 26, 2021

I've replaced straight prints with the Python logging module in my repository: https://github.com/dirkgomez/bucket-antivirus-function/blob/master/, e. g. like this:

+logging.getLogger().setLevel(level=os.getenv("LOG_LEVEL", logging.INFO))
 
 def update_defs_from_s3(s3_client, bucket, prefix):
     create_dir(AV_DEFINITION_PATH)
@@ -60,13 +52,13 @@ def update_defs_from_s3(s3_client, bucket, prefix):
             s3_time = time_from_s3(s3_client, bucket, s3_path)
 
             if s3_best_time is not None and s3_time < s3_best_time:
-                print("Not downloading older file in series: %s" % filename)
+                logging.info("Not downloading older file in series: %s" % filename)
                 continue
             else:
                 s3_best_time = s3_time

Advantages: it's configurable from within the source code what is getting logging and also from an environment variable passed into the lambda.

Would you accept a PR?

@YesemKebede
Copy link

@dirkgomez could you submit a PR for this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants