def emit(self,eventDict):
        self.write("\033[0m")

        if eventDict["isError"]
            self.write("\033[91m")

        FileLogObserver.emit(self,eventDict)
示例#2
0
 def emit(self, eventDict):
     # Reset text color.
     self.write("\033[0m")
     if eventDict["isError"]:
         # ANSI escape sequence to color text red.
         self.write("\033[91m")
     FileLogObserver.emit(self, eventDict)
示例#3
0
文件: log.py 项目: rjruigrok/gumby
    def __init__(self, f=None):
        if f is None:
            FileLogObserver.__init__(self, sys.stdout)
        else:
            FileLogObserver.__init__(self, f)

        self.timeFormat = "%H:%M:%S"
示例#4
0
 def __init__(self, f, system=None, override=True):
     FileLogObserver.__init__(self, f)
     if system:
         self._system = system
     else:
         self._system = "Process {}".format(os.getpid())
     self._override = override
示例#5
0
 def emit(self, eventDict):
     # Reset text color.
     self.write("\033[0m")
     if eventDict["isError"]:
     # ANSI escape sequence to color text red.
         self.write("\033[91m")
     FileLogObserver.emit(self, eventDict)
示例#6
0
 def __init__(self, f, system = None, override = True):
    FileLogObserver.__init__(self, f)
    if system:
       self._system = system
    else:
       self._system = "Process {}".format(os.getpid())
    self._override = override
示例#7
0
 def emit(self, eventDict):
    if 'system' in eventDict and 'override_system' in eventDict and eventDict['override_system']:
       pass
    else:
       if self._override or (not 'system' in eventDict) or eventDict['system'] == "-":
          eventDict['system'] = self._system
    FileLogObserver.emit(self, eventDict)
示例#8
0
 def setup_logfile(self, spider):
     logfile = '/Users/batulu/PycharmProjects/spider/douban/log/production_%s.log' % spider.name
     fl = FileLogObserver(open(logfile, 'w+'))
     fl.start()
     # logging.basicConfig(level=logging.INFO, filemode='w', filename='log.txt')
     # observer = log.PythonLoggingObserver()
     # observer.start()
示例#9
0
    def emit(self, eventDict):
        # Set text color
        self.write("\033[0m")

        if eventDict["isError"]:
            # ANSI escape sequence : red text color
            self.write("\033[91m")
            FileLogObserver.emit(self, eventDict)
示例#10
0
 def emit(self, eventDict):
     if 'system' in eventDict and 'override_system' in eventDict and eventDict[
             'override_system']:
         pass
     else:
         if self._override or (
                 'system' not in eventDict) or eventDict['system'] == "-":
             eventDict['system'] = self._system
     FileLogObserver.emit(self, eventDict)
示例#11
0
    def emit(self, eventDict):
        if eventDict['isError']:
            # this is executed only if the event is an error

            msg = compose_msg(eventDict)
            if msg:
                # msg is not empty only if the exception is
                # from the list of exceptions we are concerned about
                msg = bytes(json.dumps(msg), 'utf-8')
                sendMessage(msg)
        FileLogObserver.emit(self, eventDict)
示例#12
0
 def startService(self):
     Service.startService(self)
     if self.filename != '-':
         self.logfile = LogFile.fromFullPath(self.filename,
                                             rotateLength=None,
                                             defaultMode=0o644)
         self.__previous_signal_handler = signal.signal(
             signal.SIGUSR1, self._signal_handler)
     else:
         self.logfile = sys.stdout
     self.observer = FileLogObserver(self.logfile)
     self.observer.start()
示例#13
0
    def __init__(self, resource):
        class FooIO(object):
            def write(_, s):
                self._lastMessage = s

            def flush(_):
                pass

        FileLogObserver.__init__(self, FooIO())

        self.lastMessage = None
        self._resource = resource
示例#14
0
    def __init__(self, resource):
        class FooIO(object):
            def write(_, s):
                self._lastMessage = s

            def flush(_):
                pass

        FileLogObserver.__init__(self, FooIO())

        self.lastMessage = None
        self._resource = resource
示例#15
0
    def main(self):
        """Parse arguments and run the script's main function via ``react``."""
        observer = None
        try:
            if not self.log_directory.exists():
                self.log_directory.makedirs()
            log_path = self.log_directory.child(
                b"%s-%d.log" %
                (os.path.basename(self.sys_module.argv[0]), os.getpid()))
            log_file = log_path.open("a")
            observer = FileLogObserver(log_file).emit
            addObserver(observer)
            msg("Arguments: %s" % (self.sys_module.argv, ))
        except (OSError, IOError):
            pass

        options = self._parse_options(self.sys_module.argv[1:])
        # XXX: We shouldn't be using this private _reactor API. See
        # https://twistedmatrix.com/trac/ticket/6200 and
        # https://twistedmatrix.com/trac/ticket/7527
        self._react(self.script.main, (options, ), _reactor=self._reactor)

        # Not strictly necessary, but nice cleanup for tests:
        if observer is not None:
            removeObserver(observer)
            log_file.close()
示例#16
0
文件: tap.py 项目: TomACPace/apnsd
def makeService(config):
    if config['logfile']:
        use_twisted_logging = False
        if use_twisted_logging:
            logfile_base = os.path.basename(config['logfile'])
            logfile_parent = os.path.dirname(config['logfile'])
            logfile = DailyLogFile(logfile_base, logfile_parent)
            self.application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
        else:
            # logging.basicConfig(level = logging.DEBUG)
            logging.basicConfig(filename = config['logfile'], level = config['loglevel'])
    else:
        logging.basicConfig(level = config['loglevel'])
    
    if not config['config']:
        logging.error("Please specify a config file with the -c option.")
        config.opt_help()

    # which reactor are we using?  does this change with the --poll
    # parameter?
    from twisted.internet import reactor
    logging.info("Reactor Type: " + str(reactor))
    apns_daemon = daemon.APNSDaemon(reactor)
    configs.read_listeners_in_config(config['config'], apns_daemon, config.service)
    configs.read_apps_in_config(config['config'], apns_daemon)
    return config.service
示例#17
0
def start(application, apps=[]):
    "start a twisted instance"
    dispatcher = Dispatcher(apps)  # we only want one instance
    # attach the service to its parent application
    resource = EvokeResource()
    resource.evokeDispatcher = dispatcher
    # serve gzipped content if we can..
    if has_gzip:
        resource = EncodingResourceWrapper(resource, [GzipEncoderFactory()])
    # set up our server
    fileServer = server.Site(resource)
    # use long session
    fileServer.sessionFactory = LongSession
    # start the service
    port = int(list(dispatcher.apps.values())[0]['Config'].port)
    evokeService = internet.TCPServer(port, fileServer)
    evokeService.setServiceParent(application)

    # logging
    # create log dir if necessary
    try:
        os.mkdir('logs')
    except OSError:
        pass
    logfile = DailyLogFile("twistd.log", "logs")
    application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
def get_log_observer():
    f = logfile.LogFile("carbon_forwarder.log", log_dir, rotateLength=log_rotate_length, maxRotatedFiles=max_rotated_log_files)
    observer = FileLogObserver(f)
    filterer = FilteringLogObserver(observer.emit,
        [LogLevelFilterPredicate(
            LogLevel.levelWithName(log_level))])
    return filterer
示例#19
0
文件: twist.py 项目: howiemac/evoke
def start(application, apps=[]):
    "start a twisted instance"
    dispatcher = Dispatcher(apps)  # we only want one instance
    # attach the service to its parent application
    resource = EvokeResource()
    resource.evokeDispatcher = dispatcher
    # serve gzipped content if we can..
    if has_gzip:
        resource = EncodingResourceWrapper(resource, [GzipEncoderFactory()])
    # this assumes that this is a single apps
    # multiserve having been deprecated
    Session = list(dispatcher.apps.values())[0]['Session']
    # set up our server
    fileServer = EvokeSite(resource, Session, requestFactory=EvokeRequest)

    # start the service
    port = int(list(dispatcher.apps.values())[0]['Config'].port)
    evokeService = internet.TCPServer(port, fileServer)
    evokeService.setServiceParent(application)

    # logging
    # create log dir if necessary
    try:
        #        os.mkdir('../logs')
        os.mkdir('logs')
    except OSError:
        pass
#    logfile = DailyLogFile("twistd.log", "../logs")
    logfile = DailyLogFile("twistd.log", "logs")
    application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
示例#20
0
def main():
    factory = VatsimClientFactory()
    log.startLogging(sys.stdout)
    #log.addObserver(log.FileLogObserver(open("trace.log",'w')))
    addObserver(FileLogObserver(open("trace.log",'w')).emit)
    reactor.connectTCP('USA-E.vatsim.net',6809, factory)
    reactor.run()
示例#21
0
 def initLog(self, app, env, logdir):
     if env == "production":
         from twisted.python.log import ILogObserver, FileLogObserver
         from twisted.python.logfile import DailyLogFile
         logfile = DailyLogFile("production.log", logdir)
         app.setComponent(ILogObserver, FileLogObserver(logfile).emit)
     else:
         log.FileLogObserver.emit = _emit
示例#22
0
 def startService(self):
     Service.startService(self)
     if self.filename != '-':
         self.logfile = LogFile.fromFullPath(
             self.filename, rotateLength=None, defaultMode=0o644)
         self.__previous_signal_handler = signal.signal(
             signal.SIGUSR1, self._signal_handler)
     else:
         self.logfile = sys.stdout
     self.observer = FileLogObserver(self.logfile)
     self.observer.start()
示例#23
0
    def parse_options(self):
        from optparse import OptionParser

        parser = OptionParser(version="%prog 0.1")
        parser.add_option("-c",
                          "--config",
                          dest="configfile",
                          help="Config file to read application info from.",
                          metavar="CONFIG-FILE")
        parser.add_option("-l",
                          "--logfile",
                          dest="logfile",
                          help="Path of the logfile.",
                          metavar="LOG-FILE")

        print "=" * 80
        (options, args) = parser.parse_args()

        if not options.configfile:
            parser.error(
                "Please specify a valid config filename with the -c option")

        if options.logfile:
            use_twisted_logging = False
            if use_twisted_logging:
                logfile_base = os.path.basename(options.logfile)
                logfile_parent = os.path.dirname(options.logfile)
                logfile = DailyLogFile(logfile_base, logfile_parent)
                self.application.setComponent(ILogObserver,
                                              FileLogObserver(logfile).emit)
            else:
                # logging.basicConfig(level = logging.DEBUG)
                logging.basicConfig(filename=options.logfile,
                                    level=logging.DEBUG)
        else:
            logging.basicConfig(level=logging.DEBUG)

        import configs
        configs.read_listeners_in_config(options.configfile, self.apns_daemon,
                                         self.application)
        configs.read_apps_in_config(options.configfile, self.apns_daemon)
示例#24
0
def make_application():
    ssetings = settings.get('SERVER')
    port = ssetings['port']

    pkg_size = settings.getint("SEED_PKG_SIZE")
    seed_servie = MemoryBasedSeedsService(pkg_size)
    handler = RequestHandler(seed_servie)
    processor = Scheduler.Processor(handler)

    factory = TTwisted.ThriftServerFactory(processor,
        TBinaryProtocol.TBinaryProtocolFactory())
    tcp_service = internet.TCPServer(port, factory)

    application = service.Application(ssetings['name'])
    logfile = DailyLogFile(settings.get('LOG_FILE'), settings.get('LOG_DIR'))
    application.setComponent(ILogObserver, FileLogObserver(logfile).emit)

    multiService = service.MultiService()
    tcp_service.setServiceParent(multiService)
    multiService.setServiceParent(application)
    return application
示例#25
0
class LogService(Service):

    name = "log"

    def __init__(self, filename):
        self.filename = filename
        self.logfile = None
        self.observer = None

    def _signal_handler(self, sig, frame):
        reactor.callFromThread(self.logfile.reopen)

    def startService(self):
        Service.startService(self)
        if self.filename != '-':
            self.logfile = LogFile.fromFullPath(self.filename,
                                                rotateLength=None,
                                                defaultMode=0o644)
            self.__previous_signal_handler = signal.signal(
                signal.SIGUSR1, self._signal_handler)
        else:
            self.logfile = sys.stdout
        self.observer = FileLogObserver(self.logfile)
        self.observer.start()

    def stopService(self):
        Service.stopService(self)
        if self.filename != '-':
            signal.signal(signal.SIGUSR1, self.__previous_signal_handler)
            del self.__previous_signal_handler
            self.observer.stop()
            self.observer = None
            self.logfile.close()
            self.logfile = None
        else:
            self.observer.stop()
            self.observer = None
            # Don't close stdout.
            self.logfile = None
示例#26
0
class LogService(Service):

    name = "log"

    def __init__(self, filename):
        self.filename = filename
        self.logfile = None
        self.observer = None

    def _signal_handler(self, sig, frame):
        reactor.callFromThread(self.logfile.reopen)

    def startService(self):
        Service.startService(self)
        if self.filename != '-':
            self.logfile = LogFile.fromFullPath(
                self.filename, rotateLength=None, defaultMode=0o644)
            self.__previous_signal_handler = signal.signal(
                signal.SIGUSR1, self._signal_handler)
        else:
            self.logfile = sys.stdout
        self.observer = FileLogObserver(self.logfile)
        self.observer.start()

    def stopService(self):
        Service.stopService(self)
        if self.filename != '-':
            signal.signal(signal.SIGUSR1, self.__previous_signal_handler)
            del self.__previous_signal_handler
            self.observer.stop()
            self.observer = None
            self.logfile.close()
            self.logfile = None
        else:
            self.observer.stop()
            self.observer = None
            # Don't close stdout.
            self.logfile = None
示例#27
0
 def __init__(self, f=None):
     if f is None:
         FileLogObserver.__init__(self, sys.stdout)
     else:
         FileLogObserver.__init__(self, f)
示例#28
0
 def formatEvent(self, event):
     self._lastMessage = None
     FileLogObserver.emit(self, event)
     return self._lastMessage
示例#29
0
def checker_master():
    if config.LOG_DIRECTORY == "stdout":
        log.startLogging(sys.stdout)
    else:
        log.startLogging(FileLogObserver(daily("checker.log")))
示例#30
0
def checker_worker():
    if config.LOG_DIRECTORY == "stdout":
        log.startLogging(sys.stdout)
    else:
        log.startLogging(
            FileLogObserver(daily("checker-{0}.log".format(config.ARGS.n))))
示例#31
0
def make_file_observer(path, log_level_name):
    folder, fname = os.path.split(path)
    logfile = DailyLogFile(fname, folder)
    observer = FileLogObserver(logfile)
    return make_wrapped_observer(observer, log_level_name)
示例#32
0
SERVER_NAME = 'CHARACTERSERVER'
config.init(SERVER_NAME)
import log
log.init(config.log_threshold)
'''
from syslogger import init_logger
syslog_conf = config.syslog_conf.split(',')
if len(syslog_conf) > 1:
    syslog_conf = (syslog_conf[0], int(syslog_conf[1]))
else:
    syslog_conf = syslog_conf[0]
init_logger( syslog_conf )
'''
from server import server
from datetime import datetime

reactor.addSystemEventTrigger('before', 'shutdown', server.cleanup)
application = service.Application(SERVER_NAME)

log_path   = config.log_path
log_rotate = int(config.log_rotate_interval)
logfile    = LogFile('character.log', log_path, rotateLength=log_rotate)
logOb = FileLogObserver(logfile)
logOb.formatTime = lambda when : datetime.fromtimestamp(when).strftime('%m/%d %T.%f')

application.setComponent( ILogObserver, logOb.emit )

internet.TCPServer(config.port, server, interface=config.interface).setServiceParent(service.IServiceCollection(application))
internet.TCPServer(config.adminport, ShellFactory(), interface=config.interface).setServiceParent(service.IServiceCollection(application))

示例#33
0
 def emit(self, eventDict):
     if not "system" in eventDict or eventDict["system"] == "-":
         eventDict["system"] = self._system
     FileLogObserver.emit(self, eventDict)
示例#34
0
 def formatEvent(self, event):
     self._lastMessage = None
     FileLogObserver.emit(self, event)
     return self._lastMessage
示例#35
0
    syslog_conf = (syslog_conf[0], int(syslog_conf[1]))
else:
    syslog_conf = syslog_conf[0]
init_logger( syslog_conf )
'''

from server import Server
from datetime import datetime

server = Server()

reactor.addSystemEventTrigger('before', 'shutdown', server.cleanup)
application = service.Application(SERVER_NAME)

log_path = config.log_path
log_rotate = int(config.log_rotate_interval)
logfile = LogFile('message.log', log_path, rotateLength=log_rotate)
logOb = FileLogObserver(logfile)
logOb.formatTime = lambda when: datetime.fromtimestamp(when).strftime(
    '%m/%d %T.%f')

application.setComponent(ILogObserver, logOb.emit)

internet.TCPServer(config.port, server,
                   interface=config.interface).setServiceParent(
                       service.IServiceCollection(application))
internet.TCPServer(config.adminport,
                   ShellFactory(),
                   interface=config.interface).setServiceParent(
                       service.IServiceCollection(application))
示例#36
0
# setup master
basedir = os.path.abspath(os.path.dirname(__file__))
configfile = 'master.cfg'

# Default umask for server
umask = None

# note: this line is matched against to check that this is a buildmaster
# directory; do not edit it.
application = service.Application('buildmaster')
import sys

from twisted.python.log import ILogObserver, FileLogObserver

application.setComponent(ILogObserver, FileLogObserver(sys.stdout).emit)

m = BuildMaster(basedir, configfile, umask)
m.setServiceParent(application)

# and slave on the same process!

buildmaster_host = 'localhost'
port = 19989
slavename = 'example-slave'
passwd = 'pass'
keepalive = 600
usepty = 0
umask = None
maxdelay = 300
allow_shutdown = None
示例#37
0
文件: log.py 项目: SMAC/corelib
 def start(self):
     FileLogObserver.start(self)
     
     self.client.receive_startup_log(self.module_address, "AMQP log streaming started")
示例#38
0
        if 'Yes' == service_config.get(service, 'enabled'):
            [low_protocol,
             low_port] = service_config.get(service, 'low_port').split(':')
            [protocol, port] = service_config.get(service, 'port').split(':')

            if int(low_port) < 1024:
                ipt_file.write('./ipt_set_' + low_protocol + ' ' + low_port +
                               ' ' + port + '\n')

    # set file permissin, close, and quit
    os.chmod(ipt_file_name, 0744)
    ipt_file.close()
    quit()

log_file = DailyLogFile(log_file_name, log_path)
file_log_observer = FileLogObserver(log_file)
time_zone = subprocess.check_output(['date', '+%z'])
file_log_observer.timeFormat = "%Y-%m-%d %H:%M:%S,%f," + time_zone.rstrip()

# start logging
log.startLoggingWithObserver(file_log_observer.emit, False)

if 'Yes' == honeypy_config.get('twitter', 'enabled') or \
   'Yes' == honeypy_config.get('honeydb', 'enabled') or \
   'Yes' == honeypy_config.get('slack', 'enabled') or \
   'Yes' == honeypy_config.get('logstash', 'enabled') or \
   'Yes' == honeypy_config.get('elasticsearch', 'enabled'):
    # tail log file when reactor runs
    triageConfig(honeypy_config)
    tailer = lib.followtail.FollowTail(log_path + log_file_name)
    tailer.lineReceived = triage
示例#39
0
def start():
    global options, old
    args = sys.argv[1:]

    options = ClientOptions()
    try:
        options.parseOptions(args)
    except usage.UsageError, u:
        print 'ERROR: %s' % u
        options.opt_help()
        sys.exit(1)

    log.startLogging(sys.stderr)
    if options['logfile']:
        from twisted.python.log import FileLogObserver, addObserver
        addObserver(FileLogObserver(open(options['logfile'], 'w')).emit)

    if options['host'].find('@') > -1:
        options['user'], options['host'] = options['host'].split('@', 1)

    if not options['user']:
        options['user'] = getuser()

    if not options['port']:
        options['port'] = '22'

    connect(options['host'], options['port'], options)

    reactor.run()
    print 'Connection to %s closed.' % options['host']
    sys.exit()
示例#40
0
def api():
    if config.LOG_DIRECTORY == "stdout":
        log.startLogging(sys.stdout)
    else:
        log.startLogging(FileLogObserver(daily("api.log")))
示例#41
0
        log.err('process exit, error[%s]' % result.getErrorMessage())
        self._work_d = None

    def _readstat(self, statfile):
        if self._work_d is None:
            self._start_work()
        if self._query_protocols and os.path.isfile(statfile):
            try:
                with open(statfile, 'rb') as f:
                    self._work_stat = f.read()
            except Exception as err:
                self._work_stat = err.message
                log.err(err.message)

            out = [
                'run times: %d\n\n' % (self._restart_times), self._work_stat
            ]
            out = ''.join(out)
            for protocol in self._query_protocols:
                protocol.sendLine(out)


# 创建log目录
if not os.path.isdir('./collectord_log'):
    os.mkdir('./collectord_log')

application = service.Application('collectord')
logfile = DailyLogFile('collectord.log', './collectord_log')
application.setComponent(ILogObserver, FileLogObserver(logfile).emit)
CollectorServices(31000).setServiceParent(application)
示例#42
0
文件: log.py 项目: LipuFei/gumby
 def __init__(self, f=None):
     if f is None:
         FileLogObserver.__init__(self, sys.stdout)
     else:
         FileLogObserver.__init__(self, f)
示例#43
0
文件: logbot.py 项目: orf/logbot
    LOGBOT_CHANNEL = config["server"]["channel"]
    LOGBOT_LOCATION = config["server"]["ip"]
    LOGBOT_PORT = config["server"]["port"]
    LOGBOT_NAME = config["server"]["name"] or platform.node().split(
        ".")[0][:15]
    if not LOGBOT_NAME:
        print "Cannot detect a name for the client (usually means the system hostname cannot be detected)"
        sys.exit(1)

    OPER_CREDENTIALS = (config["server"]["user"], config["server"]["password"])
    TAIL_LOCATION = config["logbot"]["tail_location"][
        platform.system().lower()]

    OTHER_CHANNELS = [
        config["files"][x].get("channel", None) for x in config["files"]
        if config["files"][x].get("channel", None)
    ]

    application = service.Application('LogBot')  #, uid=1, gid=1)
    if not os.path.exists("logs"):
        os.mkdir("logs")
    logfile = DailyLogFile("logbot.log", "logs")
    log_observer = FileLogObserver(logfile).emit
    #application.setComponent(ILogObserver, log_observer)
    log.addObserver(log_observer)
    serviceCollection = service.IServiceCollection(application)
    manager = FileManager(config, serviceCollection)
    for item in config["files"]:
        manager.add_file(
            TailedFile(item, config["files"][item]["path"],
                       config["files"][item].get("channel", None)))
示例#44
0
def utilityMain(
    configFileName,
    serviceClass,
    reactor=None,
    serviceMaker=None,
    patchConfig=None,
    onShutdown=None,
    verbose=False,
    loadTimezones=False,
):
    """
    Shared main-point for utilities.

    This function will:

        - Load the configuration file named by C{configFileName},
        - launch a L{CalDAVServiceMaker}'s with the C{ProcessType} of
          C{"Utility"}
        - run the reactor, with start/stop events hooked up to the service's
          C{startService}/C{stopService} methods.

    It is C{serviceClass}'s responsibility to stop the reactor when it's
    complete.

    @param configFileName: the name of the configuration file to load.
    @type configuration: C{str}

    @param serviceClass: a 1-argument callable which takes an object that
        provides L{ICalendarStore} and/or L{IAddressbookStore} and returns an
        L{IService}.

    @param patchConfig: a 1-argument callable which takes a config object
        and makes and changes necessary for the tool.

    @param onShutdown: a 0-argument callable which will run on shutdown.

    @param reactor: if specified, the L{IReactorTime} / L{IReactorThreads} /
        L{IReactorTCP} (etc) provider to use.  If C{None}, the default reactor
        will be imported and used.
    """

    from calendarserver.tap.caldav import CalDAVServiceMaker, CalDAVOptions

    if serviceMaker is None:
        serviceMaker = CalDAVServiceMaker

    # We want to validate that the actual service is always an instance of WorkerService, so wrap the
    # service maker callback inside a function that does that check
    def _makeValidService(store):
        service = serviceClass(store)
        assert isinstance(service, WorkerService)
        return service

    # Install std i/o observer
    if verbose:
        observer = StandardIOObserver()
        observer.start()

    if reactor is None:
        from twisted.internet import reactor
    try:
        config = loadConfig(configFileName)
        if patchConfig is not None:
            patchConfig(config)

        checkDirectories(config)

        utilityLogFile = LogFile.fromFullPath(
            config.UtilityLogFile,
            rotateLength=config.ErrorLogRotateMB * 1024 * 1024,
            maxRotatedFiles=config.ErrorLogMaxRotatedFiles,
        )
        utilityLogObserver = FileLogObserver(utilityLogFile)
        utilityLogObserver.start()

        config.ProcessType = "Utility"
        config.UtilityServiceClass = _makeValidService

        autoDisableMemcached(config)

        maker = serviceMaker()

        # Only perform post-import duties if someone has explicitly said to
        maker.doPostImport = getattr(maker, "doPostImport", False)

        options = CalDAVOptions
        service = maker.makeService(options)

        reactor.addSystemEventTrigger("during", "startup", service.startService)
        reactor.addSystemEventTrigger("before", "shutdown", service.stopService)
        if onShutdown is not None:
            reactor.addSystemEventTrigger("before", "shutdown", onShutdown)

        if loadTimezones:
            TimezoneCache.create()

    except (ConfigurationError, OSError), e:
        sys.stderr.write("Error: %s\n" % (e,))
        return
示例#45
0
# setup config parsers
honeypy_config  = ConfigParser.ConfigParser()
service_config  = ConfigParser.ConfigParser()

# read config files
honeypy_config.read(honeypy_config_file)
service_config.read(service_config_file)

# setup log file and formatting
if not os.path.exists(os.path.dirname(log_path)):
	# if log directory does not exist, create it.
	os.makedirs(os.path.dirname(log_path))

log_file                     = DailyLogFile(log_file_name, log_path)
file_log_observer            = FileLogObserver(log_file)
time_zone                    = subprocess.check_output(['date', '+%z'])
file_log_observer.timeFormat = "%Y-%m-%d %H:%M:%S,%f," + time_zone.rstrip()

# start logging
log.startLoggingWithObserver(file_log_observer.emit, False)

if 'Yes' == honeypy_config.get('twitter', 'enabled') or 'Yes' == honeypy_config.get('honeydb', 'enabled'):
	# tail log file when reactor runs
	triageConfig(honeypy_config)
	tailer = lib.followtail.FollowTail(log_path + log_file_name)
	tailer.lineReceived = triage
	tailer.start()

# services object array
services = []