#!/usr/bin/env python # -*- coding: utf-8 -*- """ Logging facilities for aptdaemon """ # Copyright (C) 2013 Sebastian Heinlein <devel@glatzor.de> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. __author__ = "Sebastian Heinlein <devel@glatzor.de>" __all__ = ("ColoredFormatter") import logging import os # Define some foreground colors BLACK = 30 RED = 31 GREEN = 32 YELLOW = 33 BLUE = 34 MAGENTA = 35 CYAN = 36 WHITE = 37 # Terminal control sequences to format output RESET_SEQ = "\033[0m" COLOR_SEQ = "\033[1;%dm" BOLD_SEQ = "\033[1m" COLORS = { logging.WARN: YELLOW, logging.INFO: BLUE, logging.DEBUG: CYAN, logging.CRITICAL: RED, logging.ERROR: RED } class ColoredFormatter(logging.Formatter): """Adds some color to the log messages. http://stackoverflow.com/questions/384076/\ how-can-i-color-python-logging-output """ def __init__(self, fmt=None, datefmt=None, use_color=True): logging.Formatter.__init__(self, fmt, datefmt) if os.getenv("TERM") in ["xterm", "xterm-colored", "linux"]: self.use_color = use_color else: self.use_color = False def format(self, record): """Return the formated output string.""" if self.use_color and record.levelno in COLORS: record.levelname = (COLOR_SEQ % COLORS[record.levelno] + record.levelname + RESET_SEQ) record.name = COLOR_SEQ % GREEN + record.name + RESET_SEQ if record.levelno in [logging.CRITICAL, logging.ERROR]: record.msg = COLOR_SEQ % RED + record.msg + RESET_SEQ return logging.Formatter.format(self, record)
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
worker | Folder | 0755 |
|
|
__init__.py | File | 1.14 KB | 0644 |
|
client.py | File | 73.22 KB | 0644 |
|
config.py | File | 9 KB | 0644 |
|
console.py | File | 29.89 KB | 0644 |
|
core.py | File | 90.84 KB | 0644 |
|
crash.py | File | 2.74 KB | 0644 |
|
debconf.py | File | 6.24 KB | 0644 |
|
enums.py | File | 32.34 KB | 0644 |
|
errors.py | File | 7.28 KB | 0644 |
|
gtk3widgets.py | File | 47.17 KB | 0644 |
|
lock.py | File | 5.9 KB | 0644 |
|
logger.py | File | 2.3 KB | 0644 |
|
loop.py | File | 1.07 KB | 0644 |
|
networking.py | File | 9.7 KB | 0644 |
|
policykit1.py | File | 6.98 KB | 0644 |
|
progress.py | File | 33.4 KB | 0644 |
|
utils.py | File | 3.79 KB | 0644 |
|