wylark
/
infoex-autowx.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
56ad0a1
)
Add support for log level option
author
Alexander Vasarab <alexander@wylark.com>
Wed, 1 Jul 2020 01:24:32 +0000
(18:24 -0700)
committer
Alexander Vasarab <alexander@wylark.com>
Wed, 1 Jul 2020 01:24:32 +0000
(18:24 -0700)
infoex-autowx.py
patch
|
blob
|
history
diff --git
a/infoex-autowx.py
b/infoex-autowx.py
index 442376bafcd703ab288cfe3150947c5e3157365b..e4befadd20e8206f1ceb8d216a8c989eac657545 100755
(executable)
--- a/
infoex-autowx.py
+++ b/
infoex-autowx.py
@@
-45,7
+45,7
@@
import zeep.transports
__version__ = '2.0.0'
log = logging.getLogger(__name__)
__version__ = '2.0.0'
log = logging.getLogger(__name__)
-log.setLevel(logging.
DEBUG
)
+log.setLevel(logging.
NOTSET
)
try:
from systemd.journal import JournalHandler
try:
from systemd.journal import JournalHandler
@@
-58,39
+58,50
@@
except:
handler = logging.StreamHandler(sys.stdout)
log.addHandler(handler)
handler = logging.StreamHandler(sys.stdout)
log.addHandler(handler)
-parser = OptionParser()
+parser = OptionParser(
version=__version__
)
parser.add_option("--config",
dest="config",
metavar="FILE",
help="location of config file")
parser.add_option("--config",
dest="config",
metavar="FILE",
help="location of config file")
+parser.add_option("--log-level",
+ dest="log_level",
+ default=None,
+ help="set the log level (debug, info, warning)")
+
parser.add_option("--dry-run",
action="store_true",
dest="dry_run",
default=False,
help="fetch data but don't upload to InfoEx")
parser.add_option("--dry-run",
action="store_true",
dest="dry_run",
default=False,
help="fetch data but don't upload to InfoEx")
-parser.add_option("--version",
- action="store_true",
- dest="show_version",
- default=False,
- help="show program version and exit")
-
(options, args) = parser.parse_args()
config = configparser.ConfigParser(allow_no_value=False)
(options, args) = parser.parse_args()
config = configparser.ConfigParser(allow_no_value=False)
-if options.show_version:
- print("%s - %s" % (os.path.basename(__file__), __version__))
- sys.exit(0)
-
if not options.config:
if not options.config:
- print("Please specify a configuration file via --config.")
+ parser.print_help()
+ print("\nPlease specify a configuration file via --config.")
sys.exit(1)
config.read(options.config)
sys.exit(1)
config.read(options.config)
+# ugly, but passable
+if options.log_level in [None, 'debug', 'info', 'warning']:
+ if options.log_level == 'debug':
+ log.setLevel(logging.DEBUG)
+ elif options.log_level == 'info':
+ log.setLevel(logging.INFO)
+ elif options.log_level == 'warning':
+ log.setLevel(logging.WARNING)
+ else:
+ log.setLevel(logging.NOTSET)
+else:
+ parser.print_help()
+ print("\nPlease select an appropriate log level or remove the switch (--log-level).")
+ sys.exit(1)
+
log.debug('STARTING UP')
try:
log.debug('STARTING UP')
try: