Skip to content

Instantly share code, notes, and snippets.

@busybus
Created April 16, 2019 01:09
Show Gist options
  • Save busybus/9d8e3ddcfbcfceafc26d1f730b7a0df2 to your computer and use it in GitHub Desktop.
Save busybus/9d8e3ddcfbcfceafc26d1f730b7a0df2 to your computer and use it in GitHub Desktop.
# AUXILIARY:
# https://stackoverflow.com/questions/34491808/how-to-get-the-current-scripts-code-in-python
THIS = inspect.getsource(inspect.getmodule(inspect.currentframe()))
# Set logger verbosity and output format
logging.basicConfig(
level=logging.DEBUG,
format="%(levelname)-8s [%(asctime)s] : %(message)s",
datefmt="%Y%m%d %H:%M:%S %Z"
)
# Log which files are opened
def logged_open(filename, mode='r', *argv, **kwargs):
from builtins import open as builtin_open
logging.info("({}):\t{}".format(mode, filename))
return builtin_open(filename, mode, *argv, **kwargs)
open = logged_open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment