Skip to content

Commit

Permalink
Be able to use "-" to specify stdout be used for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Sep 13, 2013
1 parent 7d7df1a commit 148375b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/vmpoller-client
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ vmpoller-client is an application used for polling objects' information from a V
It is intended to be integrated into a Zabbix template for polling of ESX hosts and Datastores properties.
"""

import sys
import logging

from vmpoller.core import VMPollerClient
Expand Down Expand Up @@ -65,10 +66,15 @@ Options:

args = docopt(usage, version="1.0.0")

logging.basicConfig(filename=args["--logfile"],
format='%(asctime)s - %(levelname)s - vmpoller-client[%(process)s]: %(message)s',
level=logging.DEBUG)

if args["--logfile"] == "-":
logging.basicConfig(stream=sys.stdout,
format='%(asctime)s - %(levelname)s - vmpoller-client[%(process)s]: %(message)s',
level=logging.DEBUG)
else:
logging.basicConfig(filename=args["--logfile"],
format='%(asctime)s - %(levelname)s - vmpoller-client[%(process)s]: %(message)s',
level=logging.DEBUG)

client = VMPollerClient(endpoint=args["--endpoint"], retries=int(args["--retries"]), timeout=int(args["--timeout"]))

msg = { "type": "hosts" if args["--hosts"] else "datastores",
Expand Down
12 changes: 9 additions & 3 deletions src/vmpoller-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ between a pool of ZeroMQ workers.
"""

import sys
import logging

from vmpoller.core import VMPollerProxy, VMPollerClient
Expand Down Expand Up @@ -108,9 +109,14 @@ Options:

args = docopt(usage, version="1.0.0")

logging.basicConfig(filename=args["--logfile"],
format='%(asctime)s - %(levelname)s - vmpoller-proxy[%(process)s]: %(message)s',
level=logging.DEBUG)
if args["--logfile"] == "-":
logging.basicConfig(stream=stdout,
format='%(asctime)s - %(levelname)s - vmpoller-proxy[%(process)s]: %(message)s',
level=logging.DEBUG)
else:
logging.basicConfig(filename=args["--logfile"],
format='%(asctime)s - %(levelname)s - vmpoller-proxy[%(process)s]: %(message)s',
level=logging.DEBUG)

if args["start"]:
start(args["--pidfile"], args["--config"], args["--daemon"])
Expand Down
12 changes: 9 additions & 3 deletions src/vmpoller-worker
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ performing the actual polling from a vCenter server.
"""

import sys
import logging

from vmpoller.core import VMPollerWorker, VMPollerClient
Expand Down Expand Up @@ -110,9 +111,14 @@ Options:

args = docopt(usage, version="1.0.0")

logging.basicConfig(filename=args["--logfile"],
format='%(asctime)s - %(levelname)s - vmpoller-worker[%(process)s]: %(message)s',
level=logging.DEBUG)
if args["--logfile"] == "-":
logging.basicConfig(stream=sys.stdout,
format='%(asctime)s - %(levelname)s - vmpoller-worker[%(process)s]: %(message)s',
level=logging.DEBUG)
else:
logging.basicConfig(filename=args["--logfile"],
format='%(asctime)s - %(levelname)s - vmpoller-worker[%(process)s]: %(message)s',
level=logging.DEBUG)

if args["start"]:
start(args["--pidfile"], args["--config"], args["--daemon"])
Expand Down

0 comments on commit 148375b

Please sign in to comment.