Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print statements for logging #113

Open
marblestation opened this issue Oct 28, 2020 · 0 comments
Open

Print statements for logging #113

marblestation opened this issue Oct 28, 2020 · 0 comments
Assignees

Comments

@marblestation
Copy link
Contributor

marblestation commented Oct 28, 2020

To issue log messages, it would be more convenient to use the logging mechanism, such as:

try:
fp = codecs.open(out_file, 'w', 'utf-8')
except IOError, error:
logging.error("error opening file %s: %s" % (out_file, error))
return None
fp.write(xml)
logging.info("written output file %s" % out_file)

Instead of direct print statements, such as:

try:
with open(APS_ASTRO_KEYWORDS_FILE, 'rU') as fk:
for l in fk.readlines():
APS_ASTRO_KEYWORDS.append(l.strip())
except Exception as e:
print("Error loading APS Astro keywords: %s" % e)

or:

try:
conv = EntityConverter()
conv.input_text = output_metadata[ecf]
conv.convert()
output_metadata[ecf] = conv.output_text
except Exception, err:
print "problem converting %s for %s: %s" % (ecf, output_metadata['bibcode'], err)

With the logging mechanism, we will be able to set it up to log to the screen and to a file, as well as the format (e.g., JSON format so that our logging infrastructure can properly capture the fields). The python logging package allows multiple levels of logging, what we usually use:

  • info / warning / error
  • debug - We usually setup logging to print only messages up to INFO level, so the debug statements are omitted in normal operations. These are only use for debugging purposes, and it is only on those moments that we change the default level to DEBUG.
  • exception - To be used inside except so that it automatically prints the exception details without needing any argument other than the log message.

In other places we use pipeline's setup_logging and microservice's setup_logging utils to configure the logger. We could have something similar here too.

@seasidesparrow seasidesparrow self-assigned this Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants