comparison piecrust/main.py @ 564:353a0b30f412

chef: Add `--debug-only` option to only show debug logging for a given logger.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 16 Aug 2015 13:02:19 -0700
parents 186a29f61ddc
children 42a5e78e782a
comparison
equal deleted inserted replaced
563:e7fb848fd55d 564:353a0b30f412
83 self.quiet = quiet 83 self.quiet = quiet
84 self.log_file = log_file 84 self.log_file = log_file
85 self.log_debug = log_debug 85 self.log_debug = log_debug
86 self.config_variant = config_variant 86 self.config_variant = config_variant
87 self.config_values = [] 87 self.config_values = []
88 self.debug_only = []
88 89
89 90
90 def _parse_config_value(arg): 91 def _parse_config_value(arg):
91 try: 92 try:
92 name, value = arg.split('=') 93 name, value = arg.split('=')
123 elif arg == '--log': 124 elif arg == '--log':
124 res.log_file = argv[i + 1] 125 res.log_file = argv[i + 1]
125 i += 1 126 i += 1
126 elif arg == '--log-debug': 127 elif arg == '--log-debug':
127 res.log_debug = True 128 res.log_debug = True
129 elif arg == '--debug-only':
130 res.debug_only.append(argv[i + 1])
131 i += 1
128 elif arg == '--no-cache': 132 elif arg == '--no-cache':
129 res.cache = False 133 res.cache = False
130 elif arg == '--debug': 134 elif arg == '--debug':
131 res.debug = True 135 res.debug = True
132 elif arg == '--quiet': 136 elif arg == '--quiet':
144 root_logger = logging.getLogger() 148 root_logger = logging.getLogger()
145 root_logger.setLevel(logging.INFO) 149 root_logger.setLevel(logging.INFO)
146 if res.debug or res.log_debug: 150 if res.debug or res.log_debug:
147 root_logger.setLevel(logging.DEBUG) 151 root_logger.setLevel(logging.DEBUG)
148 152
153 for n in res.debug_only:
154 logging.getLogger(n).setLevel(logging.DEBUG)
155
149 log_handler = logging.StreamHandler(sys.stdout) 156 log_handler = logging.StreamHandler(sys.stdout)
150 if res.debug: 157 if res.debug or res.debug_only:
151 log_handler.setLevel(logging.DEBUG) 158 log_handler.setLevel(logging.DEBUG)
152 log_handler.setFormatter(ColoredFormatter("[%(name)s] %(message)s")) 159 log_handler.setFormatter(ColoredFormatter("[%(name)s] %(message)s"))
153 else: 160 else:
154 if res.quiet: 161 if res.quiet:
155 log_handler.setLevel(logging.WARNING) 162 log_handler.setLevel(logging.WARNING)
217 help="Sets a specific site configuration setting.") 224 help="Sets a specific site configuration setting.")
218 parser.add_argument( 225 parser.add_argument(
219 '--debug', 226 '--debug',
220 help="Show debug information.", action='store_true') 227 help="Show debug information.", action='store_true')
221 parser.add_argument( 228 parser.add_argument(
229 '--debug-only',
230 help="Only show debug information for the given categories.")
231 parser.add_argument(
222 '--no-cache', 232 '--no-cache',
223 help="When applicable, disable caching.", 233 help="When applicable, disable caching.",
224 action='store_true') 234 action='store_true')
225 parser.add_argument( 235 parser.add_argument(
226 '--quiet', 236 '--quiet',