|
2 | 2 |
|
3 | 3 | Beautifully colored, quick and simple Python logging. This logger is based on [Python logging package](https://docs.python.org/3/library/logging.html)
|
4 | 4 |
|
5 |
| -[](https://github.com/sinkingtitanic/qlogging) |
| 5 | +[](https://github.com/sinkingtitanic/qlogging) |
6 | 6 | [](https://pypi.org/project/qlogging/)
|
7 | 7 | [](https://www.python.org/downloads/)
|
8 | 8 | [](https://pypi.org/project/qlogging/)
|
@@ -92,39 +92,50 @@ Output (output format: `<date> <time> | <file_name> | <function_name>,<line#>| <
|
92 | 92 | Customize your logger based on the following `get_logger()` function parameters
|
93 | 93 |
|
94 | 94 | ```
|
95 |
| -def get_logger(level='info', logfile=None, logfilemode='a', |
96 |
| - loggingmode="short", format_str=None, format_date=None, colors=None): |
| 95 | +def get_logger( |
| 96 | + level="info", |
| 97 | + logfile=None, |
| 98 | + logfilemode="a", |
| 99 | + loggingmode="short", |
| 100 | + format_str=None, |
| 101 | + file_format_str=None, |
| 102 | + format_date=None, |
| 103 | + colors=None, |
| 104 | + logger_config=None, |
| 105 | +): |
97 | 106 | """
|
98 | 107 | returns Python logging based logger formatted with colors
|
99 | 108 |
|
100 |
| - :param level: (DEFAULT='info') str of logging level, each str option is mapped to Python logging levels, str options: |
| 109 | + :param level: (DEFAULT='info') str of logging level, each str option is mapped to Python logging levels, str options: |
101 | 110 | 'info': logging.INFO,
|
102 |
| - 'debug': logging.DEBUG, |
103 |
| - 'warning': logging.WARNING, |
104 |
| - 'error': logging.ERROR, |
| 111 | + 'debug': logging.DEBUG, |
| 112 | + 'warning': logging.WARNING, |
| 113 | + 'error': logging.ERROR, |
105 | 114 | 'critical': logging.CRITICAL,
|
106 | 115 | 'notset': logging.NOTSET
|
107 | 116 | :param logfile: (DEFAULT=None) str path where to save log file, example: '/tmp/my_log.log'
|
108 |
| - :param logfilemode: (DEFAULT='a') str of log file writing mode, same as the ones documented at Python logging package. options: |
109 |
| - 'a': appends to logfile |
110 |
| - 'w': overwrites logfile |
111 |
| - :param loggingmode: (DEFAULT='short') str logging mode to be selected. options: |
112 |
| - 'short': will use short str format ('{color}{asctime} {funcName},{lineno}| {message} {reset}') and short date format ('%H:%M:%S') |
113 |
| - 'medium': will use long str format ('color}{asctime} | {filename:8} | {funcName},{lineno} | {message}{reset}') and long date format ('%Y-%m-%d %H:%M:%S') |
| 117 | + :param logfilemode: (DEFAULT='a') str of log file writing mode, same as the ones documented at Python logging package. options: |
| 118 | + 'a': appends to logfile |
| 119 | + 'w': overwrites logfile |
| 120 | + :param loggingmode: (DEFAULT='short') str logging mode to be selected. options: |
| 121 | + 'short': will use short str format ('%(asctime)s %(funcName)s,%(lineno)s| %(message)s') and short date format ('%H:%M:%S') |
| 122 | + 'medium': will use long str format ('%(asctime)s | %(filename)s | %(funcName)s,%(lineno)s | %(message)s') and long date format ('%Y-%m-%d %H:%M:%S') |
114 | 123 | 'manual': you need to set :param format_str: and :param format_date: yourself
|
115 |
| - :param format_str: (DEFAULT=None) str of format logging string, only set this if you selected :param loggingmode: as 'manual'. example: |
116 |
| - 'color}{asctime} | {filename:8} | {funcName},{lineno} | {message}{reset}' |
117 |
| - :param date_str: (DEFAULT=None) str of date logging string, only set this if you selected :param loggingmode: as 'manual'. example: |
| 124 | + :param format_str: (DEFAULT=None) str of format logging string for console, only set this if you selected :param loggingmode: as 'manual'. example (the style is always '%', see python logging module for more info): |
| 125 | + '%(asctime)s | %(filename)s | %(funcName)s,%(lineno)s | %(message)s' |
| 126 | + :param file_format_str: (DEFAULT=None) str of format logging string for logfile (if you keep it None, we will use what you passed in :param format_str:), only set this if you selected :param loggingmode: as 'manual'. example (the style is always '%', see python logging module for more info): |
| 127 | + '%(asctime)s | %(filename)s | %(funcName)s,%(lineno)s | %(message)s' |
| 128 | + :param date_str: (DEFAULT=None) str of date logging string, only set this if you selected :param loggingmode: as 'manual'. example: |
118 | 129 | '%Y-%m-%d %H:%M:%S'
|
119 |
| - :param colors: (DEFAULT=None) dict of color settings, only set this if you selected :param loggingmode: as 'manual'. example: |
| 130 | + :param colors: (DEFAULT=None) dict of color settings, only set this if you selected :param loggingmode: as 'manual'. example: |
120 | 131 | {
|
121 | 132 | 'DEBUG': Fore.CYAN + Style.BRIGHT,
|
122 | 133 | 'INFO': Fore.GREEN + Style.BRIGHT,
|
123 | 134 | 'WARNING': Fore.YELLOW + Style.BRIGHT,
|
124 | 135 | 'ERROR': Fore.RED + Style.BRIGHT,
|
125 | 136 | 'CRITICAL': Fore.RED + Back.WHITE + Style.BRIGHT,
|
126 | 137 | }
|
127 |
| - :param logger_config: (DEFAULT=None) dict python logger config if you want to fully overwrite configs. example: |
| 138 | + :param logger_config: (DEFAULT=None) dict python logger config if you want to fully overwrite configs. example: |
128 | 139 | {
|
129 | 140 | "version": 1,
|
130 | 141 | "disable_existing_loggers": False,
|
@@ -159,7 +170,7 @@ def get_logger(level='info', logfile=None, logfilemode='a',
|
159 | 170 | },
|
160 | 171 | }
|
161 | 172 | :return: formated Python logging instance
|
162 |
| - """ |
| 173 | + """ |
163 | 174 | ```
|
164 | 175 |
|
165 | 176 | ## Alternatives
|
|
0 commit comments