| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f3cc220 commit 8badb8e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,10 +25,11 @@ | |||
| 25 | 25 | Module to handle command line argument parsing, for all front-ends. | |
| 26 | 26 | """ | |
| 27 | 27 | ||
| 28 | + import argparse | ||
| 28 | 29 | import importlib.util | |
| 30 | + import logging | ||
| 29 | 31 | import os | |
| 30 | 32 | import sys | |
| 31 | - import argparse | ||
| 32 | 33 | ||
| 33 | 34 | from . import __version__, __copyright__ | |
| 34 | 35 | from .config import default_config_path, loadini, Struct | |
@@ -118,6 +119,18 @@ def callback(group): | |||
| 118 | 119 | action="store_true", | |
| 119 | 120 | help=_("Print version and exit."), | |
| 120 | 121 | ) | |
| 122 | + parser.add_argument( | ||
| 123 | + "--log-level", | ||
| 124 | + "-l", | ||
| 125 | + choices=("debug", "info", "warning", "error", "critical"), | ||
| 126 | + default="error", | ||
| 127 | + help=_("Set log level for logging"), | ||
| 128 | + ) | ||
| 129 | + parser.add_argument( | ||
| 130 | + "--log-output", | ||
| 131 | + "-L", | ||
| 132 | + help=_("Log output file"), | ||
| 133 | + ) | ||
| 121 | 134 | ||
| 122 | 135 | if extras is not None: | |
| 123 | 136 | extras_group = parser.add_argument_group(extras[0], extras[1]) | |
@@ -147,6 +160,25 @@ def callback(group): | |||
| 147 | 160 | # Just let Python handle this | |
| 148 | 161 | os.execv(sys.executable, [sys.executable] + args) | |
| 149 | 162 | ||
| 163 | + # Configure logging handler | ||
| 164 | + bpython_logger = logging.getLogger("bpython") | ||
| 165 | + curtsies_logger = logging.getLogger("curtsies") | ||
| 166 | + bpython_logger.setLevel(options.log_level.upper()) | ||
| 167 | + curtsies_logger.setLevel(options.log_level.upper()) | ||
| 168 | + if options.log_output: | ||
| 169 | + handler = logging.FileHandler(filename=options.log_output) | ||
| 170 | + handler.setFormatter( | ||
| 171 | + logging.Formatter( | ||
| 172 | + "%(asctime)s: %(name)s: %(levelname)s: %(message)s" | ||
| 173 | + ) | ||
| 174 | + ) | ||
| 175 | + bpython_logger.addHandler(handler) | ||
| 176 | + curtsies_logger.addHandler(handler) | ||
| 177 | + bpython_logger.propagate = curtsies_logger.propagate = False | ||
| 178 | + else: | ||
| 179 | + bpython_logger.addHandler(logging.NullHandler()) | ||
| 180 | + curtsies_logger.addHandler(logging.NullHandler()) | ||
| 181 | + | ||
| 150 | 182 | config = Struct() | |
| 151 | 183 | loadini(config, options.config) | |
| 152 | 184 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,12 +129,6 @@ def main(args=None, locals_=None, banner=None, welcome_message=None): | |||
| 129 | 129 | translations.init() | |
| 130 | 130 | ||
| 131 | 131 | def curtsies_arguments(parser): | |
| 132 | - parser.add_argument( | ||
| 133 | - "--log", | ||
| 134 | - "-L", | ||
| 135 | - action="count", | ||
| 136 | - help=_("log debug messages to bpython.log"), | ||
| 137 | - ) | ||
| 138 | 132 | parser.add_argument( | |
| 139 | 133 | "--paste", | |
| 140 | 134 | "-p", | |
@@ -150,18 +144,6 @@ def curtsies_arguments(parser): | |||
| 150 | 144 | curtsies_arguments, | |
| 151 | 145 | ), | |
| 152 | 146 | ) | |
| 153 | - if options.log is None: | ||
| 154 | - options.log = 0 | ||
| 155 | - logging_levels = (logging.ERROR, logging.INFO, logging.DEBUG) | ||
| 156 | - level = logging_levels[min(len(logging_levels) - 1, options.log)] | ||
| 157 | - logging.getLogger("curtsies").setLevel(level) | ||
| 158 | - logging.getLogger("bpython").setLevel(level) | ||
| 159 | - if options.log: | ||
| 160 | - handler = logging.FileHandler(filename="bpython.log") | ||
| 161 | - logging.getLogger("curtsies").addHandler(handler) | ||
| 162 | - logging.getLogger("curtsies").propagate = False | ||
| 163 | - logging.getLogger("bpython").addHandler(handler) | ||
| 164 | - logging.getLogger("bpython").propagate = False | ||
| 165 | 147 | ||
| 166 | 148 | interp = None | |
| 167 | 149 | paste = None | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,12 +57,12 @@ The following options are supported by all frontends: | |||
| 57 | 57 | exiting. The PYTHONSTARTUP file is not read. | |
| 58 | 58 | -q, --quiet Do not flush the output to stdout. | |
| 59 | 59 | -V, --version Print :program:`bpython`'s version and exit. | |
| 60 | + -l <level>, --log-level=<level> Set logging level | ||
| 61 | + -L <file>, --log-output=<file> Set log output file | ||
| 60 | 62 | ||
| 61 | 63 | In addition to the above options, :program:`bpython` also supports the following | |
| 62 | 64 | options: | |
| 63 | 65 | ||
| 64 | - -L, --log Write debugging messages to the file bpython.log. Use | ||
| 65 | - -LL for more verbose logging. | ||
| 66 | 66 | -p file, --paste=file Paste in the contents of a file at startup. | |
| 67 | 67 | ||
| 68 | 68 | In addition to the common options, :program:`bpython-urwid` also supports the | |
| Back | FazBrowse Home | New Git URL |
0 commit comments