File: logging.py

package info (click to toggle)
python-irc 8.5.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 436 kB
  • sloc: python: 2,402; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 792 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import absolute_import

import logging

def log_level(level_string):
	"""
	Return a log level for a string
	"""
	return getattr(logging, level_string.upper())

def add_arguments(parser):
	"""
	Add arguments to an ArgumentParser or OptionParser for purposes of
	grabbing a logging level.
	"""
	adder = (
		getattr(parser, 'add_argument', None)
		or getattr(parser, 'add_option')
	)
	adder('-l', '--log-level', default=logging.INFO, type=log_level,
		help="Set log level (DEBUG, INFO, WARNING, ERROR)")

def setup(options, **kwargs):
	"""
	Setup logging with options or arguments from an OptionParser or
	ArgumentParser. Also pass any keyword arguments to the basicConfig
	call.
	"""
	params = dict(kwargs)
	params.update(level=options.log_level)
	logging.basicConfig(**params)