How to use Logentries - 10 common examples

To help you get started, we’ve selected a few Logentries 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 eleweek / WatchPeopleCode / wpc / __init__.py View on Github external
def setup_logging(loggers_and_levels, logentries_id=None):
    log = logging.getLogger('logentries')
    log.setLevel(logging.INFO)
    logentries_handler = LogentriesHandler(logentries_id)
    handler = logging.StreamHandler()

    FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s"
    formatter = logging.Formatter(fmt=FORMAT)
    handler.setFormatter(formatter)
    logentries_handler.setFormatter(formatter)

    log.addHandler(handler)
    log.addHandler(logentries_handler)
    for logger, level in loggers_and_levels:
        logger.setLevel(level)
        logger.addHandler(handler)
        logger.addHandler(logentries_handler)
github commaai / openpilot / pyextra / logentries / metrics.py View on Github external
def __init__(self, token):
        self._count = 0.0
        self._sum = 0.0
        self._lock = Lock()
        self.token = token
        handler = LogentriesHandler(token)
        log.addHandler(handler)
github eleweek / WatchPeopleCode / app.py View on Github external
def setup_logging(loggers_and_levels, logentries_id=None):
    log = logging.getLogger('logentries')
    log.setLevel(logging.INFO)
    if logentries_id:
        logentries_handler = LogentriesHandler(logentries_id)
        handler = logentries_handler
    else:
        handler = logging.StreamHandler()

    FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s"
    formatter = logging.Formatter(fmt=FORMAT)
    handler.setFormatter(formatter)

    log.addHandler(handler)
    for logger, level in loggers_and_levels:
        logger.setLevel(level)
        logger.addHandler(handler)
github commaai / openpilot / selfdrive / logmessaged.py View on Github external
def main(gctx=None):
  # setup logentries. we forward log messages to it
  le_token = "e8549616-0798-4d7e-a2ca-2513ae81fa17"
  le_handler = LogentriesHandler(le_token, use_tls=False, verbose=False)

  le_level = 20 #logging.INFO

  ctx = zmq.Context().instance()
  sock = ctx.socket(zmq.PULL)
  sock.bind("ipc:///tmp/logmessage")

  # and we publish them
  pub_sock = messaging.pub_sock('logMessage')

  while True:
    dat = b''.join(sock.recv_multipart())
    dat = dat.decode('utf8')

    # print "RECV", repr(dat)
github nir0s / feedr / feedr / transports.py View on Github external
def configure(self):
        logger = logging.getLogger('logentries')
        handler = LogentriesHandler(self.token)
        logger.addHandler(handler)
        logger.setLevel(logging.DEBUG)
        return logger
github LogentriesCommunity / le_openshift / logentries / le.py View on Github external
entry_identifier = None

            log.info("Following %s", log_filename)

            if log_token or config.datahub:
                transport = default_transport.get()
            elif log_key:
                endpoint = Domain.DATA
                port = 443
                use_ssl = not config.suppress_ssl
                if not use_ssl:
                    port = 80
                if config.force_domain:
                    endpoint = config.force_domain
                if config.debug_local:
                    endpoint = Domain.LOCAL
                    port = 8081
                    use_ssl = False
                preamble = 'PUT /%s/hosts/%s/%s/?realtime=1 HTTP/1.0\r\n\r\n' % (
                    config.user_key, config.agent_key, log_key)

                # Special case for HTTP PUT
                # Use plain formatter if no formatter is defined
                transport = Transport(endpoint, port, use_ssl, preamble, config.debug_transport_events,
                                      (config.proxy_type, config.proxy_url, config.proxy_port))
                transports.append(transport)
                # Default formatter is plain
                if not entry_formatter:
                    entry_formatter = formats.get_formatter('plain', config.hostname, log_name, log_token)
            else:
                continue
github LogentriesCommunity / le_openshift / logentries / le.py View on Github external
def api_request(request, required=False, check_status=False, silent=False, die_on_error=True):
    """
    Processes a request on the logentries domain.
    """
    # Obtain response
    response, conn = get_response(
        "POST", LE_SERVER_API, urllib.urlencode(request),
        silent=silent, die_on_error=die_on_error, domain=Domain.API,
        headers={'Content-Type': 'application/x-www-form-urlencoded'})

    # Check the response
    if not response:
        if required:
            die("Error: Cannot process LE request, no response")
        if conn:
            conn.close()
        return None
    if response.status != 200:
        if required:
            die("Error: Cannot process LE request: (%s)" % response.status)
        conn.close()
        return None

    xresponse = response.read()
github LogentriesCommunity / le_openshift / logentries / le.py View on Github external
def cmd_ls_ips(ags):
    """
    List IPs used by the agent.
    """
    l = []
    for name in [Domain.MAIN, Domain.API, Domain.DATA, Domain.PULL]:
        for info in socket.getaddrinfo(name, None, 0, 0, socket.IPPROTO_TCP):
            ip = info[4][0]
            print >>sys.stderr, '%-16s %s' % (ip, name)
            l.append(ip)
    print l
    print ' '.join(l)
github LogentriesCommunity / le_openshift / logentries / le.py View on Github external
s_entry_identifier = l['entry_identifier']
            if not s_entry_identifier:
                s_entry_identifier = config.entry_identifier
            if s_entry_identifier:
                entry_identifier = _init_entry_identifier(s_entry_identifier)
                if not entry_identifier:
                    log.error("Invalid entry separator `%s' ignored", s_entry_identifier)
            else:
                entry_identifier = None

            log.info("Following %s", log_filename)

            if log_token or config.datahub:
                transport = default_transport.get()
            elif log_key:
                endpoint = Domain.DATA
                port = 443
                use_ssl = not config.suppress_ssl
                if not use_ssl:
                    port = 80
                if config.force_domain:
                    endpoint = config.force_domain
                if config.debug_local:
                    endpoint = Domain.LOCAL
                    port = 8081
                    use_ssl = False
                preamble = 'PUT /%s/hosts/%s/%s/?realtime=1 HTTP/1.0\r\n\r\n' % (
                    config.user_key, config.agent_key, log_key)

                # Special case for HTTP PUT
                # Use plain formatter if no formatter is defined
                transport = Transport(endpoint, port, use_ssl, preamble, config.debug_transport_events,
github LogentriesCommunity / le_openshift / logentries / le.py View on Github external
def get_response(operation, addr, data=None, headers={}, silent=False, die_on_error=True, domain=Domain.API):
    """
    Returns response from the domain or API server.
    """
    response = None
    conn = None
    try:
        conn = domain_connect(config, domain, Domain)
        do_request(conn, operation, addr, data, headers)
        response = conn.getresponse()
        return response, conn
    except socket.sslerror, msg:  # Network error
        if not silent:
            log.info("SSL error: %s", msg)
    except socket.error, msg:  # Network error
        if not silent:
            log.debug("Network error: %s", msg)
    except httplib.BadStatusLine:
        error = "Internal error, bad status line"
        if die_on_error:
            die(error)
        else:
            log.info(error)