diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2018-04-01 12:28:32 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2018-04-01 12:28:32 +1000 |
| commit | cf6ac7944d08e64a1392a9ee4ec46a3624732418 (patch) | |
| tree | 54784210f3a51955e4a25face379117684f5067c /pywal/util.py | |
| parent | d5f39135b2d054af23c0af8594ee772b2a544669 (diff) | |
general: Added logging.
Diffstat (limited to 'pywal/util.py')
| -rw-r--r-- | pywal/util.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/pywal/util.py b/pywal/util.py index 65d4557..0c678c9 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -3,6 +3,7 @@ Misc helper functions. """ import colorsys import json +import logging import os import subprocess @@ -75,7 +76,7 @@ def save_file(data, export_file): with open(export_file, "w") as file: file.write(data) except PermissionError: - print("warning: Couldn't write to %s." % export_file) + logging.warning("Couldn't write to %s.", export_file) def save_file_json(data, export_file): @@ -91,6 +92,17 @@ def create_dir(directory): os.makedirs(directory, exist_ok=True) +def setup_logging(): + """Logging config.""" + logging.basicConfig(format=("[%(levelname)s\033[0m] " + "\033[1;31m%(module)s\033[0m: " + "%(message)s"), + level=logging.INFO) + logging.addLevelName(logging.ERROR, '\033[1;31mE') + logging.addLevelName(logging.INFO, '\033[1;32mI') + logging.addLevelName(logging.WARNING, '\033[1;33mW') + + def hex_to_rgb(color): """Convert a hex color to rgb.""" return tuple(bytes.fromhex(color.strip("#"))) |
