Last active
March 14, 2023 20:10
-
-
Save facundopadilla/b2210cc2311fcc576431dc1226794882 to your computer and use it in GitHub Desktop.
Anti CLRF in Python - Logging module - Log injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import sys | |
import anticrlf | |
formatter = anticrlf.LogFormatter( | |
"%(asctime)s - %(name)s - %(levelname)s: Line %(lineno)s | %(message)s" # replace it for another format | |
) | |
formatter.replacements["\n"] = "\\x0A" # OPTIONAL: \x0a is a equivalent of \n in bash | |
handler = logging.StreamHandler(sys.stdout) # another option: sys.stderr | |
handler.setFormatter(fmt=formatter) | |
logger = logging.getLogger("application") # replace the string for your application name or __name__ | |
logger.addHandler(handler) | |
logger.setLevel(logging.DEBUG) | |
logger.info("works!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment