How to use the circus.logger function in circus

To help you get started, we’ve selected a few circus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github circus-tent / circus / circus / stats / __init__.py View on Github external
help="log output")

    parser.add_argument('--version', action='store_true',
                        default=False,
                        help='Displays Circus version and exits.')

    parser.add_argument('--ssh', default=None, help='SSH Server')

    args = parser.parse_args()

    if args.version:
        print(__version__)
        sys.exit(0)

    # configure the logger
    configure_logger(logger, args.loglevel, args.logoutput)

    stats = StatsStreamer(args.endpoint, args.pubsub, args.statspoint,
                          args.ssh)

    # Register some sighandlers to stop the loop when killed
    for sig in SysHandler.SIGNALS:
        signal.signal(
            sig, lambda *_: stats.loop.add_callback_from_signal(stats.stop)
        )

    try:
        stats.start()
    finally:
        stats.stop()
        sys.exit(0)
github circus-tent / circus / circus / watcher.py View on Github external
time.sleep(timeout)
                        continue
                except OSError as e:
                    if e.errno == errno.ECHILD:
                        status = None
                    else:
                        raise

            if status is None:
                # nothing to do here, we do not have any child
                # process running
                # but we still need to send the "reap" signal.
                #
                # This can happen if poll() or wait() were called on
                # the underlying process.
                logger.debug('reaping already dead process %s [%s]',
                             pid, self.name)
                msg = {"process_pid": pid,
                       "time": time.time(),
                       "exit_code": process.returncode()}
                self.notify_event("reap", msg)
                process.stop()
                # We ignore the hook result
                self.call_hook("after_reap", process_status=None, **msg)
                return

        # get return code
        if hasattr(os, 'WIFSIGNALED'):
            exit_code = 0

            if os.WIFSIGNALED(status):
                # The Python Popen object returns <-signal> in it's returncode
github circus-tent / circus / circus / watcher.py View on Github external
close_child_stdout=self.close_child_stdout,
                                  close_child_stderr=self.close_child_stderr)

                # stream stderr/stdout if configured
                if pipe_stdout:
                    self.stdout_redirector.add_redirection('stdout',
                                                           process,
                                                           process.stdout)

                if pipe_stderr:
                    self.stderr_redirector.add_redirection('stderr',
                                                           process,
                                                           process.stderr)

                self.processes[process.pid] = process
                logger.debug('running %s process [pid %d]', self.name,
                             process.pid)
            except OSError, e:
                logger.warning('error in %r: %s', self.name, str(e))

            if process is None:
                nb_tries += 1
                continue
            else:
                self.notify_event("spawn", {"process_pid": process.pid,
                                            "time": time.time()})
                time.sleep(self.warmup_delay)
                return

        self.stop()
github circus-tent / circus / circus / stats / streamer.py View on Github external
def stop(self):
        # stop all the periodic callbacks running
        for callback in self._callbacks.values():
            callback.stop()

        self.loop.stop()
        self.ctx.destroy(0)
        self.publisher.stop()
        self.stopped = True
        self.running = False
        logger.info('Stats streamer stopped')
github circus-tent / circus / circus / papa_process_proxy.py View on Github external
def _fix_socket_name(self, s, socket_names):
        if s:
            s_lower = s.lower()
            while '$(circus.sockets.' in s_lower:
                start = s_lower.index('$(circus.sockets.')
                end = s_lower.index(')', start)
                socket_name = s_lower[start + 17:end]
                if socket_name not in socket_names:
                    logger.warning('Process "{0}" refers to socket "{1}" but '
                                   'they do not have the same "use_papa" state'
                                   .format(self.name, socket_name))
                s = ''.join((s[:start], '$(socket.circus.', socket_name,
                             '.fileno)', s[end + 1:]))
                s_lower = s.lower()
        return s
github circus-tent / circus / circus / arbiter.py View on Github external
def rm_watcher(self, name, nostop=False):
        """Deletes a watcher.

        Options:

        - **name**: name of the watcher to delete
        """
        logger.debug('Deleting %r watcher', name)

        # remove the watcher from the list
        watcher = self._watchers_names.pop(name.lower())
        watcher.notify_event("remove", {"time": time.time()})
        del self.watchers[self.watchers.index(watcher)]

        if not nostop:
            # stop the watcher
            yield watcher._stop()
github circus-tent / circus / circus / plugins / watchdog.py View on Github external
If messages are received and parsed, update the status of
        the corresponing pid.
        """
        data, _ = self.sock.recvfrom(1024)
        heartbeat = self._decode_received_udp_message(data)
        if "pid" in heartbeat:
            if heartbeat['pid'] in self.pid_status:
                # TODO: check and compare received time
                # with our own time.time()
                self.pid_status[heartbeat["pid"]][
                    'last_activity'] = time.time()
            else:
                logger.warning("received watchdog for a"
                               "non monitored process:%s",
                               heartbeat)
        logger.debug("watchdog message: %s", heartbeat)
github circus-tent / circus / circus / sockets.py View on Github external
def close_all(self):
        papa_sockets = 0
        for sock in self.values():
            sock.close()
            if isinstance(sock, PapaSocketProxy):
                papa_sockets += 1
        if papa_sockets:
            with papa.Papa() as p:
                procs = p.list_processes('circus.*')
                if not procs:
                    logger.info('removing all papa sockets')
                    p.remove_sockets('circus.*')
                    if p.exit_if_idle():
                        logger.info('closing papa')