Skip to content

Commit

Permalink
Merge pull request #22 from drdk/feature-syslog-support
Browse files Browse the repository at this point in the history
Feature syslog support
  • Loading branch information
stbrody committed Mar 12, 2013
2 parents 622ea05 + 15e13e2 commit a9cd05e
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions mongo-connector/mongo_connector.py
Expand Up @@ -19,6 +19,7 @@

import inspect
import logging
import logging.handlers
import oplog_manager
import optparse
import os
Expand Down Expand Up @@ -105,7 +106,7 @@ def __init__(self, address, oplog_checkpoint, target_url, ns_set,

if self.oplog_checkpoint is not None:
if not os.path.exists(self.oplog_checkpoint):
info_str = "MongoC`onnector: Can't find OplogProgress file!"
info_str = "MongoConnector: Can't find OplogProgress file!"
logging.critical(info_str)
self.doc_manager.stop()
self.can_run = False
Expand Down Expand Up @@ -289,18 +290,6 @@ def oplog_thread_join(self):
"""Runs mongo connector
"""

logger = logging.getLogger()
logger.setLevel(logging.INFO)

formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')

ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
ch.setFormatter(formatter)
logger.addHandler(ch)

logger.info('Beginning Mongo Connector')

parser = optparse.OptionParser()

#-m is for the main address, which is a host:port pair, ideally of the
Expand Down Expand Up @@ -408,8 +397,44 @@ def oplog_thread_join(self):
""" about making your own doc manager,"""
""" see Doc Manager section.""")

#-s is to enable syslog logging.
parser.add_option("-s","--enable-syslog", action="store_true",
dest="enable_syslog", default=False, help=
"""Used to enable logging to syslog."""
""" Use -l to specify syslog host.""")

#--syslog-host is to specify the syslog host.
parser.add_option("--syslog-host", action="store", type="string",
dest="syslog_host", default="localhost:514", help=
"""Used to specify the syslog host."""
""" The default is 'localhost:514'""")

#--syslog-facility is to specify the syslog facility.
parser.add_option("--syslog-facility", action="store", type="string",
dest="syslog_facility", default="user", help=
"""Used to specify the syslog facility."""
""" The default is 'user'""")

(options, args) = parser.parse_args()

logger = logging.getLogger()
loglevel = logging.INFO
logger.setLevel(loglevel)

if options.enable_syslog:
lh = options.syslog_host.split(":")
sh = logging.handlers.SysLogHandler(address=(lh[0], int(lh[1])),facility=options.syslog_facility)
sh.setLevel(loglevel)
logger.addHandler(sh)
else:
ch = logging.StreamHandler()
ch.setLevel(loglevel)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)

logger.info('Beginning Mongo Connector')

if options.doc_manager is None:
logger.info('No doc manager specified, using simulator.')
try:
Expand Down

0 comments on commit a9cd05e

Please sign in to comment.