Note: this is used to retrieve logs in ramuda.

    :param log_group_name: log group name
    :param start_ts: timestamp
    :param end_ts: timestamp
    :return: list of log entries
174354
def filter_log_events(awsclient, log_group_name, start_ts, end_ts=None):
    
    client_logs = awsclient.get_client('logs')
    # TODO use all_pages instead!
    logs = []
    next_token = None
    while True:
        request = {
            'logGroupName': log_group_name,
            'startTime': start_ts
        }
        if end_ts:
            request['endTime'] = end_ts
        if next_token:
            request['nextToken'] = next_token
        response = client_logs.filter_log_events(**request)
        logs.extend(
            [{'timestamp': e['timestamp'], 'message': e['message']}
             for e in response['events']]
        )
        if 'nextToken' not in response:
            break
        next_token = response['nextToken']
    return logs
525330
def delete_log_group(awsclient, log_group_name):
    
    client_logs = awsclient.get_client('logs')

    response = client_logs.delete_log_group(
        logGroupName=log_group_name
    )
323952
public function logGroups() {
        foreach($this->getGroupTotals() as $description => $total) {
            $time = number_format(round($total, 3), 3, '.', '');
            $this->getLogger()->info($description . ': ' . $time);
        }
        $this->resetGroups();
    }
631065
def start_packet_groups(self, clear_time_stamps=True, *ports):
        
        port_list = self.set_ports_list(*ports)
        if clear_time_stamps:
            self.api.call_rc('ixClearTimeStamp {}'.format(port_list))
        self.api.call_rc('ixStartPacketGroups {}'.format(port_list))
838625
def logs(self, container, tail='all', follow=False, timestamps=False):
        
        return container_logs(
            self._get_container_name(container),
            tail,
            follow,
            timestamps)
674784
def remove_log_group(self, group_name):
        
        print("Removing log group: {}".format(group_name))
        try:
            self.logs_client.delete_log_group(logGroupName=group_name)
        except botocore.exceptions.ClientError as e:
            print("Couldn't remove '{}' because of: {}".format(group_name, e))
1297445
def Logs(c_type=None, grep_list=None):
    
    def get_logs(logs, log_entries):
        try:
            for log in logs:
                if str(container.name) in log_entries:
                    log_entries[str(container.name)].append(log)
                else:
                    log_entries[str(container.name)] = [log]
        except Exception as e:  # pragma: no cover
            logger.error('Unable to get logs for ' +
                         str(container.name) +
                         ' because: ' + str(e))
        return log_entries

    status = (True, None)
    log_entries = {}
    d_client = docker.from_env()
    containers = d_client.containers.list(all=True,
                                          filters={'label': 'vent'})
    logger.debug('containers found: ' + str(containers))
    comp_c = containers
    if c_type:
        try:
            comp_c = [c for c in containers
                      if (c_type
                          in c.attrs['Config']['Labels']['vent.groups'])]
        except Exception as e:  # pragma: no cover
            logger.error('Unable to limit containers by: ' +
                         str(c_type) + ' because: ' +
                         str(e))

    if grep_list:
        for expression in grep_list:
            for container in comp_c:
                try:
                    # 'logs' stores each line containing the expression
                    logs = [log for log in container.logs().split('\n')
                            if expression in log]
                    log_entries = get_logs(logs, log_entries)
                except Exception as e:  # pragma: no cover
                    logger.info('Unable to get logs for ' +
                                str(container) +
                                ' because: ' + str(e))
    else:
        for container in comp_c:
            try:
                logs = container.logs().split('\n')
                log_entries = get_logs(logs, log_entries)
            except Exception as e:  # pragma: no cover
                logger.info('Unabled to get logs for ' +
                            str(container) +
                            ' because: ' + str(e))

    status = (True, log_entries)
    return status
920480
def get_logs(self):
        
        assert BeautifulSoup, "Please install bs4 to use this method"

        url = self.base_url + "/system/syslog.lua"
        response = self.session.get(url, params={
            'sid': self.sid,
            'stylemode': 'print',
        }, timeout=15)
        response.raise_for_status()

        entries = []
        tree = BeautifulSoup(response.text)
        rows = tree.find('table').find_all('tr')
        for row in rows:
            columns = row.find_all("td")
            date = columns[0].string
            time = columns[1].string
            message = columns[2].find("a").string

            merged = "{} {} {}".format(date, time, message.encode("UTF-8"))
            msg_hash = hashlib.md5(merged).hexdigest()
            entries.append(LogEntry(date, time, message, msg_hash))
        return entries
14459
def event_log_filter_between_date(start, end, utc):
    
    return {
        'operation': 'betweenDate',
        'options': [
            {'name': 'startDate', 'value': [format_event_log_date(start, utc)]},
            {'name': 'endDate', 'value': [format_event_log_date(end, utc)]}
        ]
    }
921582
def get_log_formats(config):
    
    # log_format name [params]
    log_format = Literal('log_format') + parameter + Group(OneOrMore(parameter)) + semicolon
    log_format.ignore(pythonStyleComment)

    for directive in log_format.searchString(config).asList():
        name = directive[1]
        format_string = ''.join(directive[2])
        yield name, format_string
175734
def log_entries_in_range(entries, start, end):
    ''''''
    start = _timestamp_from_string(start)
    end = _timestamp_from_string(end)
    for entry in entries:
        log_timestamp = entry.get('timestamp', 0)
        if log_timestamp >= start and log_timestamp <= end:
            yield entry
890607
def tail(environment, zappa_settings):
    

    def print_logs(logs):

        for log in logs:
            timestamp = log['timestamp']
            message = log['message']
            if "START RequestId" in message:
                continue
            if "REPORT RequestId" in message:
                continue
            if "END RequestId" in message:
                continue

            print("[" + str(timestamp) + "] " + message.strip())

    zappa, settings, _, lambda_name = _init(environment, zappa_settings)

    try:
        # Tail the available logs
        all_logs = zappa.fetch_logs(lambda_name)
        print_logs(all_logs)

        # Keep polling, and print any new logs.
        while True:
            all_logs_again = zappa.fetch_logs(lambda_name)
            new_logs = []
            for log in all_logs_again:
                if log not in all_logs:
                    new_logs.append(log)

            print_logs(new_logs)
            all_logs = all_logs + new_logs
    except KeyboardInterrupt:
        # Die gracefully
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)
870755
function fetchLogs(root, msg, callback) {
    const number = msg.number;
    const logfile = msg.logfile;
    const serverId = msg.serverId;
    const filePath = path.join(root, getLogFileName(logfile, serverId));

    const endLogs = [];
    exec(`tail -n ${number} ${filePath}`, (error, output) => {
        const endOut = [];
        output = output.replace(/^\s+|\s+$/g, '').split(/\s+/);

        for (let i = 5; i < output.length; i += 6) {
            endOut.push(output[i]);
        }

        const endLength = endOut.length;
        for (let j = 0; j < endLength; j++) {
            const map = {};
            let json;
            try {
                json = JSON.parse(endOut[j]);
            } catch (e) {
                logger.error(`the log cannot parsed to json, ${e}`);
                continue;   // eslint-disable-line
            }
            map.time = json.time;
            map.route = json.route || json.service;
            map.serverId = serverId;
            map.timeUsed = json.timeUsed;
            map.params = endOut[j];
            endLogs.push(map);
        }

        callback({ logfile: logfile, dataArray: endLogs });
    });
}
1078641
private void doGroupStart(final JsonObject message) {
    String groupID = message.getString("group");
    String name = message.getString("name");
    String parentId = message.getString("parent");
    Object args = deserializer.deserialize(message);
    DefaultConnectionInputGroup group = new DefaultConnectionInputGroup(groupID, name, this);
    groups.put(groupID, group);
    if (parentId != null) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("%s - Group started: Group[name=%s, group=%s, parent=%s, args=%s]", this, name, groupID, parentId, args));
      }
      if (currentBatch != null && parentId.equals(currentBatch.id())) {
        currentBatch.handleGroup(group);
      } else {
        DefaultConnectionInputGroup parent = groups.get(parentId);
        if (parent != null) {
          parent.handleGroup(group);
        }
      }
    } else {
      if (log.isDebugEnabled()) {
        log.debug(String.format("%s - Group started: Group[name=%s, group=%s, args=%s]", this, name, groupID, args));
      }
      // First check for a named group handler. If a named group handler isn't
      // registered then trigger the arbitrary group handler if one is registered.
      Handler<InputGroup> handler = groupHandlers.get(name);
      if (handler != null) {
        handler.handle(group);
      } else if (groupHandler != null) {
        groupHandler.handle(group);
      } else {
        groupReady(groupID);
      }
    }
    group.handleStart(args);
  }
466364
def process_log_group(config):
    

    from c7n.credentials import SessionFactory
    factory = SessionFactory(
        config.region, config.profile, assume_role=config.role)
    session = factory()
    client = session.client('logs')

    params = dict(logGroupName=config.log_group,
                  filterPattern='Traceback', interleaved=True)
    if config.log_streams:
        params['logStreamNames'] = config.log_streams

    if config.start:
        params['startTime'] = int(time.mktime(
            parse_date(config.start).replace(
                hour=0, minute=0, second=0, microsecond=0).timetuple()) * 1000)
    if config.end:
        params['endTime'] = int(time.mktime(
            parse_date(config.end).replace(
                hour=0, minute=0, second=0, microsecond=0).timetuple()) * 1000)

    settings = dict(account_id=config.account_id,
                    account_name=config.account_name)
    paginator = client.get_paginator('filter_log_events')

    event_count = 0
    log.debug("Querying log events with %s", params)
    for p in paginator.paginate(**params):
        # log.debug("Searched streams\n %s", ", ".join(
        #    [s['logStreamName'] for s in p['searchedLogStreams']]))
        for e in p['events']:
            event_count += 1
            msg = get_sentry_message(
                settings, {'logEvents': [e],
                           'logStream': e['logStreamName'],
                           'logGroup': config.log_group}, client)
            if msg is None:
                continue
            send_sentry_message(config.sentry_dsn, msg)

    if event_count > 0:
        log.info("Processed %s %d error events", config.account_name, event_count)
754742
def tail(self, since, filter_pattern, limit=10000, keep_open=True, colorize=True, http=False, non_http=False, force_colorize=False):
        

        try:
            since_stamp = string_to_timestamp(since)

            last_since = since_stamp
            while True:
                new_logs = self.zappa.fetch_logs(
                    self.lambda_name,
                    start_time=since_stamp,
                    limit=limit,
                    filter_pattern=filter_pattern,
                    )

                new_logs = [ e for e in new_logs if e['timestamp'] > last_since ]
                self.print_logs(new_logs, colorize, http, non_http, force_colorize)

                if not keep_open:
                    break
                if new_logs:
                    last_since = new_logs[-1]['timestamp']
                time.sleep(1)
        except KeyboardInterrupt: # pragma: no cover
            # Die gracefully
            try:
                sys.exit(0)
            except SystemExit:
                os._exit(130)
1129729
def getlog(start, end, deplist=['00'], modlist=['M0'], xlsx=None):
    '''
        
    '''
    # entry point url
    api = 'http://www.insee.fr/fr/methodes/nomenclatures/cog/recherche_historique.asp'
    # build payloads
    if modlist == ['M0']:
        modlist = ['MA', 'MB', 'MC', 'MD', 'ME', 'MF', 'MG']
    payloads = [{'debut':start, 'fin':end, 'dep':dep, 'mod':mod} for dep in deplist for mod in modlist]
    # send requests
    results = [pg2df(requests.get(api, params=payload)) for payload in payloads]
    # make a df and fine tune it (force dtypes)
    data = pd.concat(results)
    data.reset_index()
    data['date'] = pd.to_datetime(data['date'], format='%d/%m/%Y')
    data[['dep', 'depcom', 'mod', 'obs']] = data[['dep', 'depcom', 'mod', 'obs']].astype(object)
    # write xlsx
    if xlsx:
        pd.core.format.header_style = None
        data.to_excel(xlsx, index=False)
    
    return pd.concat(results)