예제 #1
0
 def run_normal(self):
     if self.debug:
         log.startLogging(sys.stdout)
     else:
         log.startLogging(DailyLogFile.fromFullPath(self.logfile))
     log.msg("portal server listen %s" % self.portal_host)
     reactor.listenUDP(self.listen_port, self, interface=self.portal_host)
예제 #2
0
파일: lumen.py 프로젝트: unsouled/lumen
def makeService(_config):
    global config
    config = _config

    if config['logpath'] != None:
        logFilePath = os.path.abspath(config['logpath'])
        logFile = DailyLogFile.fromFullPath(logFilePath)
    else:
        logFile = sys.stdout

    log.startLogging(logFile)

    lumenService = service.MultiService()

    # Bayeux Service
    import bayeux
    bayeuxFactory = bayeux.BayeuxServerFactory()
    bayeuxService = internet.TCPServer(config['port'], bayeuxFactory)
    bayeuxService.setServiceParent(lumenService)

    # WebConsole Service
    import webconsole
    site = server.Site(webconsole.WebConsole())
    webConsoleService = internet.TCPServer(config['webport'], site)
    webConsoleService.setServiceParent(lumenService)

    application = service.Application("lumen")
    lumenService.setServiceParent(application)

    return lumenService
예제 #3
0
 def run_normal(self):
     if self.debug:
         log.startLogging(sys.stdout)
     else:
         log.startLogging(DailyLogFile.fromFullPath(self.logfile))
     log.msg('server listen %s' % self.radiusd_host)
     reactor.listenUDP(self.authport,
                       self.auth_protocol,
                       interface=self.radiusd_host)
     reactor.listenUDP(self.acctport,
                       self.acct_protocol,
                       interface=self.radiusd_host)
     if self.use_ssl:
         log.msg('WS SSL Enable!')
         from twisted.internet import ssl
         sslContext = ssl.DefaultOpenSSLContextFactory(
             self.privatekey, self.certificate)
         reactor.listenSSL(self.adminport,
                           self.admin_factory,
                           contextFactory=sslContext,
                           interface=self.radiusd_host)
     else:
         reactor.listenTCP(self.adminport,
                           self.admin_factory,
                           interface=self.radiusd_host)
     if not self.standalone:
         reactor.run()
예제 #4
0
파일: ux.py 프로젝트: dmpayton/hendrix
def noiseControl(options):
    # terminal noise/info logic
    # allows the specification of the log file location
    if not options["loud"]:
        log_path = options["log"]
        log.startLogging(DailyLogFile.fromFullPath(log_path))
    return None
예제 #5
0
 def run_normal(self):
     if self.debug:
         log.startLogging(sys.stdout)
     else:
         log.startLogging(DailyLogFile.fromFullPath(self.logfile))
     log.msg('portal server listen %s' % self.portal_host)
     reactor.listenUDP(self.listen_port, self, interface=self.portal_host)
예제 #6
0
def make_logfile_observer(path, show_source=False):
    """
    Make an observer that writes out to C{path}.
    """
    from twisted.logger import FileLogObserver
    from twisted.python.logfile import DailyLogFile

    f = DailyLogFile.fromFullPath(path)

    def _render(event):

        if event.get("log_system", u"-") == u"-":
            logSystem = u"{:<10} {:>6}".format("Controller", os.getpid())
        else:
            logSystem = event["log_system"]

        if show_source and event.get("log_namespace") is not None:
            logSystem += " " + event.get("cb_namespace", event.get("log_namespace", ''))

        if event.get("log_format", None) is not None:
            eventText = formatEvent(event)
        else:
            eventText = ""

        if "log_failure" in event:
            # This is a traceback. Print it.
            eventText = eventText + event["log_failure"].getTraceback()

        eventString = NOCOLOUR_FORMAT.format(
            formatTime(event["log_time"]), logSystem, eventText) + os.linesep

        return eventString

    return FileLogObserver(f, _render)
예제 #7
0
def init(conf):
    """Creates all the required object to run the program

    Args:
        conf: Config object.

    Returns:
        ControlServer object.
    """
    # Setup logger
    logPath = path.join(conf['dataDir'], 'logs/server.log')
    logFile = DailyLogFile.fromFullPath(logPath)
    log.startLogging(logFile)

    # Create DHT Server
    server = yield initServer(conf['serverPort'], conf['bootStrapServer'],
                              8468)
    dht = DHTServer(server)

    # Create key and cert management objects
    keyStore = keystore.KeyStore(conf['dataDir'])
    keys = KeyManager(dht, keyStore)
    certs = CertManager(dht, keyStore)
    aclDir = path.join(conf['dataDir'], 'acl')
    verifier = Verifier(certs, keyStore, aclDir, conf["searchDepth"])

    # Return value so it doesn't get garbage collected
    returnValue(
        ControlServer(conf['localPort'], dht, keys, certs, verifier, keyStore,
                      reactor))
예제 #8
0
def init_logging(logdir, logname):
    if DEBUG_LEVEL > 0:
        log.startLogging(sys.stdout)
    if not os.path.exists(logdir):
        os.makedirs(logdir)
    logfile = get_path(os.path.join(logdir, logname))
    log.startLogging(DailyLogFile.fromFullPath(logfile))
예제 #9
0
def make_logfile_observer(path, show_source=False):
    """
    Make an observer that writes out to C{path}.
    """
    from twisted.logger import FileLogObserver
    from twisted.python.logfile import DailyLogFile

    f = DailyLogFile.fromFullPath(path)

    def _render(event):

        if event.get("log_system", u"-") == u"-":
            logSystem = u"{:<10} {:>6}".format("Controller", os.getpid())
        else:
            logSystem = event["log_system"]

        if show_source and event.get("log_namespace") is not None:
            logSystem += " " + event.get("cb_namespace",
                                         event.get("log_namespace", ''))

        if event.get("log_format", None) is not None:
            eventText = formatEvent(event)
        else:
            eventText = ""

        if "log_failure" in event:
            # This is a traceback. Print it.
            eventText = eventText + event["log_failure"].getTraceback()

        eventString = NOCOLOUR_FORMAT.format(formatTime(event["log_time"]),
                                             logSystem, eventText) + os.linesep

        return eventString

    return FileLogObserver(f, _render)
예제 #10
0
	def __init__(self):
		try:
			logfile = DailyLogFile.fromFullPath(cfg.logging.filename)
		except AssertionError:
			raise AssertionError("Assertion error attempting to open the log file: {0}. Does the directory exist?".format(cfg.logging.filename))

		twistedlogger.startLogging(logfile, setStdout=False)
예제 #11
0
    def _createLogFile(self, uuid):
        logDirPath = '{cwd}\\..\\logs\\aiprocesses'.format(cwd=os.getcwd())
        if not os.path.exists(logDirPath):
            os.mkdir(logDirPath)

        logFilePath = '{dir}\\{uuid}.log'.format(dir=logDirPath, uuid=uuid)
        log.startLogging(DailyLogFile.fromFullPath(logFilePath))
예제 #12
0
def start_logging(opts):
    from twisted.python import log
    from twisted.python.logfile import DailyLogFile
    if opts.logfile:
        logfile = DailyLogFile.fromFullPath(opts.logfile)
    else:
        logfile = sys.stderr
    log.startLogging(logfile)
예제 #13
0
 def start_logging(self):
     """Starts logging to log file or stdout depending on config."""
     if self.use_log:
         if self.log_stdout:
             log.startLogging(sys.stdout)
         else:
             log_file = os.path.expanduser(self.log_file)
             log.startLogging(DailyLogFile.fromFullPath(log_file))
예제 #14
0
def main(nickname):
    log.startLogging(sys.stdout)
    log.startLogging(DailyLogFile.fromFullPath(
        os.path.join(settings.LOG_DIRECTORY, nickname + '.log')),
                     setStdout=1)
    factory = TwitterTrackerClientFactory(TwitterJob, nickname)
    reactor.connectTCP(settings.JT_HOSTNAME, settings.JT_PORT, factory)
    reactor.run()
예제 #15
0
파일: logging.py 프로젝트: cbrinley/droned
def logToDir(directory='logs', LOG_TYPE=('console',), OBSERVER=MyLogObserver):
    """Call this to write logs to the specified directory,
       optionally override the FileLogObserver.
    """
    for name in LOG_TYPE:
        path = os.path.join(directory, name + '.log')
        logfile = DailyLogFile.fromFullPath(path)
        logs[name] = OBSERVER(logfile)
예제 #16
0
def init_config(cfgfile):
    config = ConfigParser.SafeConfigParser(__defconfig__)
    config.read(cfgfile)
    if config.getboolean('DEFAULT', 'debug'):
        log.startLogging(sys.stdout)
    else:
        log.startLogging(
            DailyLogFile.fromFullPath(config.get("DEFAULT", 'logfile')))
    return config
예제 #17
0
def start_logging(opts):
    from twisted.python import log
    from twisted.python.logfile import DailyLogFile
    if opts.logfile:
        logfile = DailyLogFile.fromFullPath(opts.logfile)
    else:
        logfile = sys.stderr
    log.startLogging(logfile)
    log.msg("Open files limit: %d" % resource.getrlimit(resource.RLIMIT_NOFILE)[0])
예제 #18
0
    def _handle_logging(self):
        """
        Start logging to file if there is some file configuration and we
        are not running in development mode
        """

        if self.development is False and self._log_file is not None:
            self.already_logging = True
            log.startLogging(DailyLogFile.fromFullPath(self.log_file))
예제 #19
0
    def __init__(self, args=None):
        '''Args must be an object with the following attributes:
           foreground, logfile, mailbox, nClients, silent, socketpath, verbose
           Suitable defaults will be supplied.'''

        # Pass command line args to ProtocolIVSHMSG, then open logging.
        if args is None:
            args = argparse.Namespace()
        for arg, default in self._required_arg_defaults.items():
            setattr(args, arg, getattr(args, arg, default))

        # Mailbox may be sized above the requested number of clients to
        # satisfy QEMU IVSHMEM restrictions.
        args.server_id = args.nClients + 1
        args.nEvents = args.nClients + 2

        # It's a singleton so no reason to keep the instance, however it's
        # the way I wrote the Klein API server so...
        mb = MB(args=args)
        MailBoxReSTAPI(mb)
        shutdown_http_logging()

        if args.foreground:
            if args.verbose > 1:
                TPlog.startLogging(sys.stdout, setStdout=False)
            else:
                TPlog.startLogging(open('/dev/null', 'a'), setStdout=False)
        else:
            PRINT('Logging to %s' % args.logfile)
            TPlog.startLogging(
                DailyLogFile.fromFullPath(args.logfile),
                setStdout=True)  # "Pass-through" explicit print() for debug
        args.logmsg = TPlog.msg
        args.logerr = TPlog.err

        # By Twisted version 18, "mode=" is deprecated and you should just
        # inherit the tacky bit from the parent directory.  wantPID creates
        # <path>.lock as a symlink to "PID".
        E = UNIXServerEndpoint(
            TIreactor,
            args.socketpath,
            mode=0o666,  # Deprecated at Twisted 18
            wantPID=True)
        E.listen(self)
        args.logmsg(
            '%s server @%d ready for %d clients on %s' %
            (args.title, args.server_id, args.nClients, args.socketpath))

        # https://stackoverflow.com/questions/1411281/twisted-listen-to-multiple-ports-for-multiple-processes-with-one-reactor

        # Voodoo kick to a) set up one-time SI and b)setup commander.
        # Docs mislead, have to explicitly pass something to get persistent
        # state across protocol/transport invocations.  As there is only
        # one server object per process instantion, that's not necessary.

        protobj = ProtocolIVSHMSGServer(self, args)  # With "args"
        Commander(protobj)
예제 #20
0
파일: app.py 프로젝트: DamnWidget/mamba
    def _handle_logging(self):
        """
        Start logging to file if there is some file configuration and we
        are not running in development mode
        """

        if self.development is False and self._log_file is not None:
            self.already_logging = True
            log.startLogging(DailyLogFile.fromFullPath(self.log_file))
예제 #21
0
    def __init__(self):
        try:
            logfile = DailyLogFile.fromFullPath(cfg.logging.filename)
        except AssertionError:
            raise AssertionError(
                "Assertion error attempting to open the log file: {0}. Does the directory exist?"
                .format(cfg.logging.filename))

        twistedlogger.startLogging(logfile, setStdout=False)
예제 #22
0
def setup_logging():
    if not os.path.exists(settings.LOG_DIR):
        os.makedirs(settings.LOG_DIR)
    if settings.LOG_FILE:
        logfile = DailyLogFile.fromFullPath(
            os.path.join(settings.LOG_DIR, settings.LOG_FILE))
    else:
        logfile = sys.stderr
    observer = ScrapyrtFileLogObserver(logfile)
    startLoggingWithObserver(observer.emit, setStdout=False)
예제 #23
0
파일: conf.py 프로젝트: TigerND/dtx-core
def configure(**options):
    global logLevel, logFile
    LEVELS = {
        'debug': logging.DEBUG,
        'info': logging.INFO,
        'warning': logging.WARNING,
        'error': logging.ERROR,
        'critical': logging.CRITICAL
    }

    logLevel = LEVELS[options.get('loglevel', 'info').lower()]
    logging.basicConfig(level=logLevel)

    logFile = options.get('logfile', None)
    if logFile:
        # defaultMode=0644 # workaround for https://twistedmatrix.com/trac/ticket/7026
        log.startLogging(DailyLogFile.fromFullPath(logFile,defaultMode=0644))
    else:
        log.startLogging(sys.stdout)
예제 #24
0
    def init(cls, target='stdout', log_level=2, filename='twistd.log'):
        cls.filename = filename
        cls.target = target
        cls.log_level = log_level

        if cls.target is 'file':
            logfile = get_filename(filename=cls.filename)
            log.startLogging(DailyLogFile.fromFullPath(logfile))
        else:
            log.startLogging(stdout)
예제 #25
0
def main(options):

    connection = settings.REDIS_CLASS()

    log.startLogging(sys.stdout)
    log.startLogging(DailyLogFile.fromFullPath(os.path.join(settings.LOG_DIRECTORY, 'master.log')), setStdout=1)
    log.addObserver(RedisLogObserver(connection).emit)

    factory = TwitterJobTrackerFactory(connection, TwitterJob, settings.MAX_CLIENTS, options=options)
    reactor.listenTCP(settings.JT_PORT + options.ha, factory)
    reactor.run()
예제 #26
0
파일: log.py 프로젝트: agz1990/scrapyrt
def setup_logging():
    if not os.path.exists(settings.LOG_DIR):
        os.makedirs(settings.LOG_DIR)
    if settings.LOG_FILE:
        logfile = DailyLogFile.fromFullPath(
            os.path.join(settings.LOG_DIR, settings.LOG_FILE)
        )
    else:
        logfile = sys.stderr
    observer = ScrapyrtFileLogObserver(logfile)
    startLoggingWithObserver(observer.emit, setStdout=False)
예제 #27
0
파일: server.py 프로젝트: Bzisch/splash
def start_logging(opts):
    import twisted
    from twisted.python import log
    if opts.logfile:
        from twisted.python.logfile import DailyLogFile
        logfile = DailyLogFile.fromFullPath(opts.logfile)
    else:
        logfile = sys.stderr
    flo = log.startLogging(logfile)

    if twisted.version.major >= 13:  # add microseconds to log
        flo.timeFormat = "%Y-%m-%d %H:%M:%S.%f%z"
예제 #28
0
def start_logging(opts):
    import twisted
    from twisted.python import log
    from twisted.python.logfile import DailyLogFile
    if opts.logfile:
        logfile = DailyLogFile.fromFullPath(opts.logfile)
    else:
        logfile = sys.stderr
    flo = log.startLogging(logfile)

    if twisted.version.major >= 13:  # add microseconds to log
        flo.timeFormat = "%Y-%m-%d %H:%M:%S.%f%z"
예제 #29
0
파일: app.py 프로젝트: aroshni/mamba
    def __init__(self, options=None):
        """Mamba constructor"""

        super(Mamba, self).__init__()

        self.monkey_patched = False
        self.already_logging = False
        self._mamba_ver = _mamba_version.version.short()
        self._ver = _app_ver.short()
        self._port = 1936
        self._log_file = None
        self._project_ver = _app_project_ver.short()

        self.name = 'Mamba Webservice v%s' % _mamba_version.version.short()
        self.description = (
            'Mamba %s is a Web applications framework that works '
            'over Twisted using Jinja2 as GUI enhancement '
            'Mamba has been developed by Oscar Campos '
            '<*****@*****.**>' % _mamba_version.version.short()
        )

        self.language = os.environ.get('LANG', 'en_EN').split('_')[0]
        self.lessjs = False

        self._parse_options(options)

        # monkey patch twisted
        self._monkey_patch()

        # register log file if any
        if self.log_file is not None:
            self.already_logging = True
            log.startLogging(DailyLogFile.fromFullPath(self.log_file))

        # PyPy does not implement set_debug method in gc object
        if getattr(options, 'debug', False):
            if hasattr(gc, 'set_debug'):
                gc.set_debug(gc.DEBUG_STATS | gc.DEBUG_INSTANCES)
            else:
                log.msg(
                    'Debug is set as True but gc object is laking '
                    'set_debug method'
                )

        self._header = headers.Headers()
        self._header.language = self.language
        self._header.description = self.description

        self.managers = {
            'controller': controller.ControllerManager(),
            'model': model.ModelManager()
        }
예제 #30
0
def start():
    from twisted.python import log
    from twisted.python.logfile import DailyLogFile
    from twisted.internet import reactor

    if settings['devMode'] == False:     
        #Setup WebSocket
        log.startLogging(DailyLogFile.fromFullPath(settings['release']['log']))

        factory = WebSocketServerFactory(u"ws://127.0.0.1:9001")
        factory.protocol = ServerRobotController

        reactor.listenTCP(9001, factory)
        reactor.run()
예제 #31
0
 def start(self):
   ''' Start a daemon, bittorrent tracker, bittorrent client '''
   from flowcontrol import FlowControl
   from twisted.internet import reactor
   from twisted.python import log
   from twisted.python.logfile import DailyLogFile
   log.startLogging(DailyLogFile.fromFullPath(self.f.log_dir + "btcp.log"))
   #self.tt = bttracker(self.ts_name) # !!! Code bttracker() !!!
   #self.ts = bttorrent(self.ts_name) # !!! Code btTorrent() !!!
   self.fc = FlowControl(f=self.f) # !!! Code FlowControle() !!!
   reactor.callLater(self.interval, self.fc._tick) # schedule to run next time in self.interval 
   reactor.callLater(self.interval + 10, self.fc._tack) # schedule to run next time in self.interval 
   self.blog.debug('BtCP.start: started!')
   ''' !!! Code me !!! '''
예제 #32
0
    def __init__(self, options=None):
        """Mamba constructor"""

        super(Mamba, self).__init__()

        self.monkey_patched = False
        self.already_logging = False
        self._mamba_ver = _mamba_version.version.short()
        self._ver = _app_ver.short()
        self._port = 1936
        self._log_file = None
        self._project_ver = _app_project_ver.short()

        self.name = 'Mamba Webservice v%s' % _mamba_version.version.short()
        self.description = (
            'Mamba %s is a Web applications framework that works '
            'over Twisted using Jinja2 as GUI enhancement '
            'Mamba has been developed by Oscar Campos '
            '<*****@*****.**>' % _mamba_version.version.short())

        self.language = os.environ.get('LANG', 'en_EN').split('_')[0]
        self.lessjs = False

        self._parse_options(options)

        # monkey patch twisted
        self._monkey_patch()

        # register log file if any
        if self.log_file is not None:
            self.already_logging = True
            log.startLogging(DailyLogFile.fromFullPath(self.log_file))

        # PyPy does not implement set_debug method in gc object
        if getattr(options, 'debug', False):
            if hasattr(gc, 'set_debug'):
                gc.set_debug(gc.DEBUG_STATS | gc.DEBUG_INSTANCES)
            else:
                log.msg('Debug is set as True but gc object is laking '
                        'set_debug method')

        self._header = headers.Headers()
        self._header.language = self.language
        self._header.description = self.description

        self.managers = {
            'controller': controller.ControllerManager(),
            'model': model.ModelManager()
        }
예제 #33
0
def main(options):

    connection = settings.REDIS_CLASS()

    log.startLogging(sys.stdout)
    log.startLogging(DailyLogFile.fromFullPath(
        os.path.join(settings.LOG_DIRECTORY, 'master.log')),
                     setStdout=1)
    log.addObserver(RedisLogObserver(connection).emit)

    factory = TwitterJobTrackerFactory(connection,
                                       TwitterJob,
                                       settings.MAX_CLIENTS,
                                       options=options)
    reactor.listenTCP(settings.JT_PORT + options.ha, factory)
    reactor.run()
예제 #34
0
    def run_normal(self):
        if self.debug:
            log.startLogging(sys.stdout)
        else:
            log.startLogging(DailyLogFile.fromFullPath(self.logfile))
        log.msg("server listen %s" % self.host)
        if self.use_ssl:
            log.msg("Control SSL Enable!")
            from twisted.internet import ssl

            sslContext = ssl.DefaultOpenSSLContextFactory(self.privatekey, self.certificate)
            reactor.listenSSL(self.port, self.web_factory, contextFactory=sslContext, interface=self.host)
        else:
            reactor.listenTCP(self.port, self.web_factory, interface=self.host)
        if not self.standalone:
            reactor.run()
예제 #35
0
파일: page.py 프로젝트: aroshni/mamba
    def __init__(self, app):
        resource.Resource.__init__(self)

        self.app = app
        self._controllers_manager = None
        self._stylesheets = []
        self._scripts = []

        # register log file if any
        if app.already_logging is False and app.log_file is not None:
            log.startLogging(DailyLogFile.fromFullPath(app.log_file))

        # set managers
        self._controllers_manager = app.managers.get('controller')

        # register controllers
        self.register_controllers()
예제 #36
0
def make_legacy_daily_logfile_observer(path, logoutputlevel):
    """
    Make a L{DefaultSystemFileLogObserver}.
    """
    from crossbar.twisted.processutil import DefaultSystemFileLogObserver
    from twisted.logger import LegacyLogObserverWrapper
    from twisted.python.logfile import DailyLogFile

    logfd = DailyLogFile.fromFullPath(os.path.join(path,
                                                   'node.log'))
    flo = LegacyLogObserverWrapper(
        DefaultSystemFileLogObserver(logfd,
                                     system="{:<10} {:>6}".format(
                                         "Controller", os.getpid())).emit)

    def _log(event):

        level = event["log_level"]

        if logoutputlevel == "none":
            return
        elif logoutputlevel == "quiet":
            # Quiet: Only print warnings and errors to stderr.
            if level not in (LogLevel.warn, LogLevel.error, LogLevel.critical):
                return
        elif logoutputlevel == "standard":
            # Standard: For users of Crossbar
            if level not in (LogLevel.info, LogLevel.warn, LogLevel.error,
                             LogLevel.critical):
                return
        elif logoutputlevel == "verbose":
            # Verbose: for developers
            # Adds the class source.
            if event.get("cb_level") == "trace":
                return
        elif logoutputlevel == "trace":
            # Verbose: for developers
            # Adds "trace" output
            pass
        else:
            assert False, "Shouldn't ever get here."

        # Forward the event
        flo(event)

    return _log
예제 #37
0
    def __init__(self, app, template_paths=None, cache_size=50, loader=None):
        resource.Resource.__init__(self)

        # register log file if any
        if (app.development is False and
                app.already_logging is False and app.log_file is not None):
            log.startLogging(DailyLogFile.fromFullPath(app.log_file))

        self._contained_controllers = []
        self._assets = resource.Assets([os.getcwd() + '/static'])
        self.template_paths = [
            'application/view/templates',
            '{}/templates/jinja'.format(
                os.path.dirname(__file__).rsplit(os.sep, 1)[0]
            )
        ]

        # set managers
        self._controllers_manager = app.managers.get('controller')
        self._shared_controllers_manager = app.managers.get('packages')

        # register controllers
        self.register_shared_controllers()
        self.register_controllers()

        # containers
        self.containers = {
            'styles': static.Data('', 'text/css'),
            'scripts': static.Data('', 'text/javascript')
        }
        # register containers
        self.putChild('styles', self.containers['styles'])
        self.putChild('scripts', self.containers['scripts'])
        # insert stylesheets and scripts
        self.insert_stylesheets()
        self.insert_scripts()
        # register service ponger
        self.putChild('_mamba_pong', static.Data('PONG', 'text/plain'))

        # static accessible data (scripts, css, images, and others)
        self.putChild('assets', self._assets)

        # other initializations
        self.generate_dispatches()
        self.initialize_templating_system(template_paths, cache_size, loader)
예제 #38
0
def make_legacy_daily_logfile_observer(path, logoutputlevel):
    """
    Make a L{DefaultSystemFileLogObserver}.
    """
    from crossbar.twisted.processutil import DefaultSystemFileLogObserver
    from twisted.logger import LegacyLogObserverWrapper
    from twisted.python.logfile import DailyLogFile

    logfd = DailyLogFile.fromFullPath(os.path.join(path, 'node.log'))
    flo = LegacyLogObserverWrapper(
        DefaultSystemFileLogObserver(logfd,
                                     system="{:<10} {:>6}".format(
                                         "Controller", os.getpid())).emit)

    def _log(event):

        level = event["log_level"]

        if logoutputlevel == "none":
            return
        elif logoutputlevel == "quiet":
            # Quiet: Only print warnings and errors to stderr.
            if level not in (LogLevel.warn, LogLevel.error, LogLevel.critical):
                return
        elif logoutputlevel == "standard":
            # Standard: For users of Crossbar
            if level not in (LogLevel.info, LogLevel.warn, LogLevel.error,
                             LogLevel.critical):
                return
        elif logoutputlevel == "verbose":
            # Verbose: for developers
            # Adds the class source.
            if event.get("cb_level") == "trace":
                return
        elif logoutputlevel == "trace":
            # Verbose: for developers
            # Adds "trace" output
            pass
        else:
            assert False, "Shouldn't ever get here."

        # Forward the event
        flo(event)

    return _log
예제 #39
0
def run_command_start(options):
    """
   Subcommand "crossbar start".
   """
    ## start Twisted logging
    ##
    if not options.logdir:
        logfd = sys.stderr
    else:
        from twisted.python.logfile import DailyLogFile
        logfd = DailyLogFile.fromFullPath(
            os.path.join(options.logdir, 'node.log'))

    from crossbar.twisted.processutil import DefaultSystemFileLogObserver
    flo = DefaultSystemFileLogObserver(logfd,
                                       system="{:<10} {:>6}".format(
                                           "Controller", os.getpid()))
    log.startLoggingWithObserver(flo.emit)

    log.msg("=" * 30 + " Crossbar.io " + "=" * 30 + "\n")

    import crossbar
    log.msg("Crossbar.io {} starting".format(crossbar.__version__))

    ## we use an Autobahn utility to import the "best" available Twisted reactor
    ##
    reactor = install_reactor(options.reactor, options.debug)

    from twisted.python.reflect import qual
    log.msg("Running on {} using {} reactor".format(
        platform.python_implementation(),
        qual(reactor.__class__).split('.')[-1]))
    log.msg("Starting from node directory {}".format(options.cbdir))

    ## create and start Crossbar.io node
    ##
    from crossbar.controller.node import Node
    node = Node(reactor, options)
    node.start()

    try:
        log.msg("Entering reactor event loop ...")
        reactor.run()
    except Exception as e:
        log.msg("Could not start reactor: {0}".format(e))
예제 #40
0
 def run_normal(self):
     if self.debug:
         log.startLogging(sys.stdout)
     else:
         log.startLogging(DailyLogFile.fromFullPath(self.logfile))
     log.msg('portal web server listen %s'%self.host)
     if self.use_ssl:
         log.msg('Portal SSL Enable!')
         from twisted.internet import ssl
         sslContext = ssl.DefaultOpenSSLContextFactory(self.privatekey, self.certificate)
         reactor.listenSSL(
             self.port,
             self.web_factory,
             contextFactory = sslContext,
             interface=self.host
         )
     else:
         reactor.listenTCP(self.port, self.web_factory,interface=self.host)
예제 #41
0
파일: page.py 프로젝트: cypreess/mamba
    def __init__(self, app):
        resource.Resource.__init__(self)

        self.app = app
        self._controllers_manager = None
        self._stylesheets = []
        self._scripts = []

        # register log file if any
        if (app.development is False and
                app.already_logging is False and app.log_file is not None):
            log.startLogging(DailyLogFile.fromFullPath(app.log_file))

        # set managers
        self._controllers_manager = app.managers.get('controller')

        # register controllers
        self.register_controllers()
예제 #42
0
def main():
    if len(sys.argv) < 2:
        print "Usage: %s config_file" % sys.argv[0]
        sys.exit()

    log.startLogging(sys.stdout)

    Config.init(sys.argv[1])

    if Config.debug:
        log.startLogging(sys.stdout)
    else:
        log.startLogging(DailyLogFile.fromFullPath(Config.get("log.file")))

    handler = SnowflakeServiceHandler(Config.getint("worker.id"), Config.getint("datacenter.id"))
    processor = SnowflakeService.Processor(handler)
    server = TTwisted.ThriftServerFactory(processor=processor, iprot_factory=TBinaryProtocol.TBinaryProtocolFactory())
    reactor.listenTCP(Config.getint("port", default=9999), server, interface=Config.get("listen", default="0.0.0.0"))
    reactor.run()
예제 #43
0
파일: conf.py 프로젝트: nnseva/dtx-core
def configure(**options):
    global logLevel, logFile
    LEVELS = {
        'debug': logging.DEBUG,
        'info': logging.INFO,
        'warning': logging.WARNING,
        'error': logging.ERROR,
        'critical': logging.CRITICAL
    }

    logLevel = LEVELS[options.get('loglevel', 'info').lower()]
    logging.basicConfig(level=logLevel)

    logFile = options.get('logfile', None)
    if logFile:
        # defaultMode=0644 # workaround for https://twistedmatrix.com/trac/ticket/7026
        log.startLogging(DailyLogFile.fromFullPath(logFile, defaultMode=0644))
    else:
        log.startLogging(sys.stdout)
예제 #44
0
파일: page.py 프로젝트: olivecoder/mamba
    def __init__(self, app, template_paths=None, cache_size=50, loader=None):
        resource.Resource.__init__(self)

        # register log file if any
        if (app.development is False and app.already_logging is False
                and app.log_file is not None):
            log.startLogging(DailyLogFile.fromFullPath(app.log_file))

        self._assets = resource.Assets([os.getcwd() + '/static'])
        self.template_paths = [
            'application/view/templates', '{}/templates/jinja'.format(
                os.path.dirname(__file__).rsplit(os.sep, 1)[0])
        ]

        # set managers
        self._controllers_manager = app.managers.get('controller')
        self._shared_controllers_manager = app.managers.get('packages')

        # register controllers
        self.register_shared_controllers()
        self.register_controllers()

        # containers
        self.containers = {
            'styles': static.Data('', 'text/css'),
            'scripts': static.Data('', 'text/javascript')
        }
        # register containers
        self.putChild('styles', self.containers['styles'])
        self.putChild('scripts', self.containers['scripts'])
        # insert stylesheets and scripts
        self.insert_stylesheets()
        self.insert_scripts()
        # register service ponger
        self.putChild('_mamba_pong', static.Data('PONG', 'text/plain'))

        # static accessible data (scripts, css, images, and others)
        self.putChild('assets', self._assets)

        # other initializations
        self.generate_dispatches()
        self.initialize_templating_system(template_paths, cache_size, loader)
예제 #45
0
def setup_logging():
    if not os.path.exists(galaxy_settings.LOG_DIR):
        os.makedirs(galaxy_settings.LOG_DIR)
    if galaxy_settings.LOG_FILE:
        logfile = DailyLogFile.fromFullPath(
            os.path.join(galaxy_settings.LOG_DIR, galaxy_settings.LOG_FILE))
    else:
        logfile = sys.stderr
    observer = GalaxyFileLogObserver(logfile, galaxy_settings.LOG_ENCODING)
    startLoggingWithObserver(observer.emit, setStdout=False)

    # setup general logging for Scrapy
    if not sys.warnoptions:
        # Route warnings through python logging
        logging.captureWarnings(True)

    observer = log.PythonLoggingObserver('twisted')
    observer.start()
    logging.root.setLevel(logging.NOTSET)
    dictConfig(DEFAULT_LOGGING)
예제 #46
0
 def set_logging(self):
   ''' set logging based on self.standalone, with self.logLevel verbosity
   if standalone enabled - write to console
   otherwise - log to twisted.python module  
   '''
   level = getattr(logging,self.logLevel)  # get logging level value from logging module by 'logLevel' name (DEBUG|INFO|WARNING)
   if self.standalone:
     ch = logging.StreamHandler()
     ch.setLevel(level)
     self.blog = logging.getLogger('btcpstandalone')
     self.blog.addHandler(ch)
     self.blog.setLevel(level)
     self.blog.debug('btcp standalone loaded, __name__: %s' %(__name__,))
   else:
     from twisted.python import log
     from twisted.python.logfile import DailyLogFile
     log.startLogging(DailyLogFile.fromFullPath(self.f.log_dir + "flowcontrol.log"))
     self.blog = logging.getLogger('btcp')
     self.blog.setLevel(level)
     self.blog.debug('btcp loaded, __name__: %s' %(__name__,))
예제 #47
0
def main(argv):
    """ Usage python listener.py -f path/to/conf-file or python listener.py"""
    try:
        opts, args = getopt.getopt(argv, "f:h", ["config-file", "help"])
    except getopt.GetoptError:
        print main.__doc__
        exit(1)
    if len(opts) == 0:
        CONF = configobj.ConfigObj("config/app.conf")
    else:
        for opt, arg in opts:
            if opt in ("-f", "--config-file"):
                CONF = configobj.ConfigObj(arg)
    print "configs are :"
    print CONF
    __builtin__.app = globals()[CONF['logic']]()
    print "write pid to file -> %s" % (CONF['pid-file'])
    with open(CONF['pid-file'], "wb") as fd:
        fd.write("%d" % getpid())
    print "[listener->pid:%d]: app lunched " % (getpid())
    print "[listener->pid:%d]: depoloying signals handler" % (getpid())
    signal.signal(signal.SIGHUP, signal_handler)
    signal.signal(signal.SIGUSR1, signal_handler)
    print "[listener->pid:%d]: load configs" % (getpid())
    loadConfiguration(app, CONF['lists'])
    _file = CONF['log-file']
    print "[listener->pid:%d]: load counters " % (getpid())
    c = counter.Counter(CONF['counter-path'])
    __builtin__.COUNTER = c.increment
    print "[listener->pid:%d]: Register logger to the app" % (getpid())
    print "[listener->pid:%d]: Registering app to the listeners .." % (
        getpid())
    for port in CONF['ports'].split(','):  # 2 ranges odd and even
        reactor.listenTCP(int(port), server.Site(app))
        print "[listener->pid:%d]:\tport:%d" % (getpid(), int(port))
    print "[listener->pid:%d] deploy logger at file %s" % (getpid(), _file)
    #__builtin__.log =
    log.startLogging(DailyLogFile.fromFullPath(_file))
    log.msg("[listener->pid:%d]: starting .." % (getpid(), ))
    reactor.run()
예제 #48
0
def main():
    writelog('starting server')
    if len(sys.argv) > 1 and sys.argv[1] == 'debug':
        log.startLogging(sys.stdout)
        debug = True

#print 'debuggin'
    else:
        debug = False
    log.startLogging(DailyLogFile.fromFullPath("/var/log/sprinkler.log"))
    debug = True
    contextFactory = ssl.DefaultOpenSSLContextFactory(
        '/home/pi/cron/keys/server.key', '/home/pi/cron/keys/server.crt')
    ServerFactory = BroadcastServerFactory
    #ServerFactory = BroadcastPreparedServerFactory

    factory = ServerFactory("wss://localhost:5000",
                            debug=debug,
                            debugCodePaths=debug)
    factory2 = ServerFactory("ws://localhost:5001",
                             debug=debug,
                             debugCodePaths=debug)

    factory.protocol = BroadcastServerProtocol
    factory.setProtocolOptions(allowHixie76=True)
    factory2.protocol = BroadcastServerProtocol
    factory2.setProtocolOptions(allowHixie76=True)
    listenWS(factory2)
    listenWS(factory, contextFactory)
    webdir = File("/home/pi/cron/sprinklerwww/")
    web = Site(webdir)
    web.protocol = HTTPChannelHixie76Aware
    webdir.contentTypes['.crt'] = 'application/x-x509-ca-cert'
    print 'starting server'
    webdir.putChild("sChange", sChange())
    webdir.putChild("schedule", schedule())
    webdir.putChild("manual", manual())
    #reactor.listenTCP(8080, web)
    reactor.listenSSL(8081, web, contextFactory)
    reactor.run()
예제 #49
0
파일: cli.py 프로젝트: akashaio/crossbar
def run_command_start(options):
   """
   Subcommand "crossbar start".
   """
   ## start Twisted logging
   ##
   if not options.logdir:
      logfd = sys.stderr
   else:
      from twisted.python.logfile import DailyLogFile
      logfd = DailyLogFile.fromFullPath(os.path.join(options.logdir, 'node.log'))

   from crossbar.twisted.processutil import DefaultSystemFileLogObserver
   flo = DefaultSystemFileLogObserver(logfd, system = "{:<10} {:>6}".format("Controller", os.getpid()))
   log.startLoggingWithObserver(flo.emit)

   log.msg("=" * 30 + " Crossbar.io " + "=" * 30 + "\n")

   import crossbar
   log.msg("Crossbar.io {} starting".format(crossbar.__version__))

   ## we use an Autobahn utility to import the "best" available Twisted reactor
   ##
   reactor = install_reactor(options.reactor, options.debug)

   from twisted.python.reflect import qual
   log.msg("Running on {} using {} reactor".format(platform.python_implementation(), qual(reactor.__class__).split('.')[-1]))
   log.msg("Starting from node directory {}".format(options.cbdir))

   ## create and start Crossbar.io node
   ##
   from crossbar.controller.node import Node
   node = Node(reactor, options)
   node.start()

   try:
      log.msg("Entering reactor event loop ...")
      reactor.run()
   except Exception as e:
      log.msg("Could not start reactor: {0}".format(e))
예제 #50
0
파일: listener.py 프로젝트: AShabana/gproxy
def main(argv):
	""" Usage python listener.py -f path/to/conf-file or python listener.py"""
	try :
		opts, args = getopt.getopt(argv, "f:h", ["config-file","help"])
	except getopt.GetoptError:
		print main.__doc__
		exit(1)
	if len(opts) == 0 :
		CONF = configobj.ConfigObj("config/app.conf")
	else :
		for opt,arg in opts:
			if opt in ("-f", "--config-file"):
				CONF = configobj.ConfigObj(arg)
	print "configs are :"
	print CONF
	__builtin__.app = globals()[CONF['logic']]() 
	print "write pid to file -> %s" %(CONF['pid-file'])
	with open(CONF['pid-file'],"wb") as fd :
		fd.write("%d" % getpid())
	print "[listener->pid:%d]: app lunched " %(getpid())
	print "[listener->pid:%d]: depoloying signals handler" %(getpid())
	signal.signal(signal.SIGHUP, signal_handler)
	signal.signal(signal.SIGUSR1, signal_handler)
	print "[listener->pid:%d]: load configs" %(getpid())
	loadConfiguration(app, CONF['lists'])
	_file = CONF['log-file']
	print "[listener->pid:%d]: load counters "  %(getpid())
	c = counter.Counter(CONF['counter-path'])
	__builtin__.COUNTER = c.increment
	print "[listener->pid:%d]: Register logger to the app" % (getpid())
	print "[listener->pid:%d]: Registering app to the listeners .." %(getpid())
	for port in CONF['ports'].split(','): # 2 ranges odd and even
		reactor.listenTCP(int(port), server.Site(app))
		print "[listener->pid:%d]:\tport:%d" %(getpid(), int(port))
	print "[listener->pid:%d] deploy logger at file %s" %(getpid(), _file) 
	#__builtin__.log = 
	log.startLogging(DailyLogFile.fromFullPath(_file))
	log.msg("[listener->pid:%d]: starting .." % (getpid(),))
	reactor.run()
예제 #51
0
 def run_normal(self):
     if self.debug:
         log.startLogging(sys.stdout)
     else:
         log.startLogging(DailyLogFile.fromFullPath(self.logfile))
     log.msg('server listen %s'%self.radiusd_host)  
     reactor.listenUDP(self.authport, self.auth_protocol,interface=self.radiusd_host)
     reactor.listenUDP(self.acctport, self.acct_protocol,interface=self.radiusd_host)
     if self.use_ssl:
         log.msg('WS SSL Enable!')
         from twisted.internet import ssl
         sslContext = ssl.DefaultOpenSSLContextFactory(self.privatekey, self.certificate)
         reactor.listenSSL(
             self.adminport,
             self.admin_factory,
             contextFactory = sslContext,
             interface=self.radiusd_host
         )
     else:
         reactor.listenTCP(self.adminport, self.admin_factory,interface=self.radiusd_host)
     if not self.standalone:
         reactor.run()
예제 #52
0
파일: log.py 프로젝트: SmileyJames/scrapyrt
def setup_logging():
    if not os.path.exists(scrapyrt_settings.LOG_DIR):
        os.makedirs(scrapyrt_settings.LOG_DIR)
    if scrapyrt_settings.LOG_FILE:
        logfile = DailyLogFile.fromFullPath(
            os.path.join(scrapyrt_settings.LOG_DIR,
                         scrapyrt_settings.LOG_FILE)
        )
    else:
        logfile = sys.stderr
    observer = ScrapyrtFileLogObserver(logfile, scrapyrt_settings.LOG_ENCODING)
    startLoggingWithObserver(observer.emit, setStdout=False)

    # setup general logging for Scrapy
    if not sys.warnoptions:
        # Route warnings through python logging
        logging.captureWarnings(True)

    observer = log.PythonLoggingObserver('twisted')
    observer.start()
    logging.root.setLevel(logging.NOTSET)
    dictConfig(DEFAULT_LOGGING)
예제 #53
0
    def __init__(self, args=None):
        '''Args must be an object with the following attributes:
           foreground, logfile, mailbox, nClients, silent, socketpath, verbose
           Suitable defaults will be supplied.'''

        # Pass command line args to ProtocolIVSHMSG, then open logging.
        if args is None:
            args = argparse.Namespace()
        for arg, default in self._required_arg_defaults.items():
            setattr(args, arg, getattr(args, arg, default))

        # Mailbox may be sized above the requested number of clients to
        # satisfy QEMU IVSHMEM restrictions.
        args.server_id = args.nClients + 1
        args.nEvents = args.nClients + 2
        FAMEZ_MailBox(args=args)  # singleton class, no need to keep instance

        self.cmdlineargs = args
        if args.foreground:
            TPlog.startLogging(sys.stdout, setStdout=False)
        else:
            PRINT('Logging to %s' % args.logfile)
            TPlog.startLogging(
                DailyLogFile.fromFullPath(args.logfile),
                setStdout=True)  # "Pass-through" explicit print() for debug
        args.logmsg = TPlog.msg
        args.logerr = TPlog.err

        # By Twisted version 18, "mode=" is deprecated and you should just
        # inherit the tacky bit from the parent directory.  wantPID creates
        # <path>.lock as a symlink to "PID".
        E = UNIXServerEndpoint(
            TIreactor,
            args.socketpath,
            mode=0o666,  # Deprecated at Twisted 18
            wantPID=True)
        E.listen(self)
        args.logmsg('FAME-Z server @%d ready for %d clients on %s' %
                    (args.server_id, args.nClients, args.socketpath))
예제 #54
0
def main():
    if len(sys.argv) < 2:
        print 'Usage: %s config_file' % sys.argv[0]
        sys.exit()

    log.startLogging(sys.stdout)

    Config.init(sys.argv[1])

    if Config.debug:
        log.startLogging(sys.stdout)
    else:
        log.startLogging(DailyLogFile.fromFullPath(Config.get('log.file')))

    handler = SnowflakeServiceHandler(Config.getint('worker.id'),
                                      Config.getint('datacenter.id'))
    processor = SnowflakeService.Processor(handler)
    server = TTwisted.ThriftServerFactory(
        processor=processor,
        iprot_factory=TBinaryProtocol.TBinaryProtocolFactory())
    reactor.listenTCP(Config.getint('port', default=9999),
                      server,
                      interface=Config.get('listen', default="0.0.0.0"))
    reactor.run()
예제 #55
0
파일: server.py 프로젝트: aleozlx/pacswitch
def run(**options):
    if 'ENABLE_TERMINAL_EVENT_FEED' in options:
        global ENABLE_TERMINAL_EVENT_FEED
        ENABLE_TERMINAL_EVENT_FEED = options['ENABLE_TERMINAL_EVENT_FEED']
    if 'LOGFILE_FULLPATH' in options:
        from twisted.python.logfile import DailyLogFile
        global ENABLE_LOGFILE
        ENABLE_LOGFILE = True
        log.startLogging(DailyLogFile.fromFullPath(
            options['LOGFILE_FULLPATH']),
                         setStdout=False)
    if 'ADMIN_KEY' in options:
        admin.ADMIN_KEY = options['ADMIN_KEY']
        reactor.listenTCP(3511, admin.Factory())
    assert 'DB_CONNECTION' in options
    import mysql.connector
    db.getConnection = lambda: mysql.connector.connect(**options[
        'DB_CONNECTION'])
    db.debug = debug
    admin.UserDB = db.UserDB
    # reactor.listenUDP(3513, P2pDataSwitch())
    reactor.listenTCP(3512, ServerFactory())
    reactor.callLater(900, tcpGC)
    reactor.run()
예제 #56
0
# Aether imports
from InputOutput import aetherProtocol
from DecisionEngine import eventLoop
from ORM import Demeter

# Without this line, the networking process can't communicate with main on Windows when frozen.
# Possibly also valid for OS X. Ignore PyCharm 'unused import' warning.

if globals.userProfile.get(
        'debugDetails', 'debugLogging'
):  # Debug enabled. Keep print enabled, and route it to the logs.
    from twisted.python import log
    from twisted.python.logfile import DailyLogFile
    log.startLogging(
        DailyLogFile.fromFullPath(PROFILE_DIR + '/Logs/network.log'))
    globals.logSystemDetails()

else:  # Debug not enabled. Disable print

    def print(*a, **kwargs):
        pass


if FROZEN:
    print('Networking Daemon: I am frozen.')
else:
    print('Networking Daemon: I am thawed.')


def main():
예제 #57
0
import sys
import re
from sympy import sympify
from twisted.web.static import File
from twisted.python import log
from twisted.web.server import Site
from twisted.internet import reactor

from autobahn.twisted.websocket import WebSocketServerFactory, \
    WebSocketServerProtocol

from autobahn.twisted.resource import WebSocketResource

from twisted.python.logfile import DailyLogFile

log.startLogging(DailyLogFile.fromFullPath("server.log"))


class SomeServerProtocol(WebSocketServerProtocol):
    def onOpen(self):
        try:
            self.factory.register(self)
        except:
            pass

    def connectionLost(self, reason):
        try:
            self.factory.unregister(self)
        except:
            pass