// matchLogLine tries to match a log line by trying to match each key value pair with each pair of key value regexes
// if matchAll is true then matchLogLine returns true iff every key value regexes finds a match or the line or regexes
// are empty
482884
func matchLogLine(keyvals []interface{}, keyRegexes, valueRegexes []*regexp.Regexp, matchAll bool) bool {
	all := matchAll
	// We should be passed an aligned list of keyRegexes and valueRegexes, but since we can't error here we'll guard
	// against a failure of the caller to pass valid arguments
	length := len(keyRegexes)
	if len(valueRegexes) < length {
		length = len(valueRegexes)
	}
	for i := 0; i < length; i++ {
		matched := findMatchInLogLine(keyvals, keyRegexes[i], valueRegexes[i])
		if matchAll {
			all = all && matched
		} else if matched {
			return true
		}
	}
	return all
}
814197
func (l *FileLog) matchingFiles(fromUTC, toUTC time.Time) ([]eventFile, error) {
	var dirs []string
	var err error
	if l.SearchDirs != nil {
		dirs, err = l.SearchDirs()
		if err != nil {
			return nil, trace.Wrap(err)
		}
	} else {
		dirs = []string{l.Dir}
	}

	var filtered []eventFile
	for _, dir := range dirs {
		// scan the log directory:
		df, err := os.Open(dir)
		if err != nil {
			return nil, trace.Wrap(err)
		}
		defer df.Close()
		entries, err := df.Readdir(-1)
		if err != nil {
			return nil, trace.Wrap(err)
		}
		for i := range entries {
			fi := entries[i]
			if fi.IsDir() || filepath.Ext(fi.Name()) != LogfileExt {
				continue
			}
			fd, err := parseFileTime(fi.Name())
			if err != nil {
				l.Warningf("Failed to parse audit log file %q format: %v", fi.Name(), err)
				continue
			}
			// File rounding in current logs is non-deterministic,
			// as Round function used in rotateLog can round up to the lowest
			// or the highest period. That's why this has to check both
			// periods.
			// Previous logic used modification time what was flaky
			// as it could be changed by migrations or simply moving files
			if fd.After(fromUTC.Add(-1*l.RotationPeriod)) && fd.Before(toUTC.Add(l.RotationPeriod)) {
				eventFile := eventFile{
					FileInfo: fi,
					path:     filepath.Join(dir, fi.Name()),
				}
				filtered = append(filtered, eventFile)
			}
		}
	}
	// sort all accepted files by date
	sort.Sort(byDate(filtered))
	return filtered, nil
}
957290
func (as ArraySpec) Log10() Input {
	return as.proc(func(i Input) Input {
		return i.Log10()
	})
}
770388
func Logs(c *client.Client, appID string, lines int) (string, error) {
	u := fmt.Sprintf("/v1/apps/%s/logs", appID)

	if lines > 0 {
		u += "?log_lines=" + strconv.Itoa(lines)
	}

	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return "", err
	}

	return strings.Trim(body, `"`), nil
}
614064
func (l *LogLevelType) Matches(v LogLevelType) bool {
	c := l.Value()
	return c&v == v
}
70575
func (m *Matcher) Lines() []string {
	m.mut.Lock()
	defer m.mut.Unlock()
	return m.lines
}
224182
func matches(s, pattern string) bool {
	return regexp.MustCompile(pattern).MatchString(s)
}
1235377
func (l *LogParserPlugin) TOML() string {
	s := make([]string, len(l.Files))
	for k, v := range l.Files {
		s[k] = strconv.Quote(v)
	}
	return fmt.Sprintf(`[[inputs.%s]]	
  ## Log files to parse.
  ## These accept standard unix glob matching rules, but with the addition of
  ## ** as a "super asterisk". ie:
  ##   /var/log/**.log     -> recursively find all .log files in /var/log
  ##   /var/log/*/*.log    -> find all .log files with a parent dir in /var/log
  ##   /var/log/apache.log -> only tail the apache log file
  files = [%s]

  ## Read files that currently exist from the beginning. Files that are created
  ## while telegraf is running (and that match the "files" globs) will always
  ## be read from the beginning.
  from_beginning = false
  ## Method used to watch for file updates.  Can be either "inotify" or "poll".
  # watch_method = "inotify"
  ## Parse logstash-style "grok" patterns:
  [inputs.logparser.grok]
    ## This is a list of patterns to check the given log file(s) for.
    ## Note that adding patterns here increases processing time. The most
    ## efficient configuration is to have one pattern per logparser.
    ## Other common built-in patterns are:
    ##   %%{COMMON_LOG_FORMAT}   (plain apache & nginx access logs)
    ##   %%{COMBINED_LOG_FORMAT} (access logs + referrer & agent)
    patterns = ["%%{COMBINED_LOG_FORMAT}"]
    ## Name of the outputted measurement name.
    measurement = "apache_access_log"
`, l.PluginName(), strings.Join(s, ", "))
}
234261
func (logger *Logger) Log(level Level, v ...interface{}) {
	// Don't delete this calling. The calling is used to keep the same
	// calldepth for all the logging functions. The calldepth is used to
	// get runtime information such as line number, function name, etc.
	logger.log(level, v...)
}
400468
func matchExactRegex(v string) ([]string, bool) {
	re, err := syntax.Parse(v, syntax.Perl)
	if err != nil {
		// Nothing we can do or log.
		return nil, false
	}
	re = re.Simplify()

	if re.Op != syntax.OpConcat {
		return nil, false
	}

	if len(re.Sub) < 2 {
		// Regex has too few subexpressions.
		return nil, false
	}

	start := re.Sub[0]
	if !(start.Op == syntax.OpBeginLine || start.Op == syntax.OpBeginText) {
		// Regex does not begin with ^
		return nil, false
	}

	end := re.Sub[len(re.Sub)-1]
	if !(end.Op == syntax.OpEndLine || end.Op == syntax.OpEndText) {
		// Regex does not end with $
		return nil, false
	}

	// Remove the begin and end text from the regex.
	re.Sub = re.Sub[1 : len(re.Sub)-1]

	if len(re.Sub) == 0 {
		// The regex /^$/
		return nil, true
	}
	return matchRegex(re)
}
1215147
func onelinelog(ctx context.Context, workingDir, refspec string, subdirs []string) ([]Commit, error) {
	out := &bytes.Buffer{}
	args := []string{"log", "--pretty=format:%GK|%H|%s", refspec}
	args = append(args, "--")
	if len(subdirs) > 0 {
		args = append(args, subdirs...)
	}

	if err := execGitCmd(ctx, args, gitCmdConfig{dir: workingDir, out: out}); err != nil {
		return nil, err
	}

	return splitLog(out.String())
}
1196484
func (cl *ChannelLogger) FlushLogLines() [][]interface{} {
	logLines := make([][]interface{}, 0, cl.ch.Len())
	cl.Flush(log.LoggerFunc(func(keyvals ...interface{}) error {
		logLines = append(logLines, keyvals)
		return nil
	}))
	return logLines
}
842349
func matchStreams(streams []*coordinator.LogStream, pattern string) []*coordinator.LogStream {
	// Filter results that match the requested stream name.
	// ** turns into .*
	// * turns into [^/]*
	doubles := strings.Split(pattern, "**")
	for i, d := range doubles {
		singles := strings.Split(d, "*")
		for j, s := range singles {
			singles[j] = regexp.QuoteMeta(s)
		}
		doubles[i] = strings.Join(singles, "[^/]*")
	}
	r := regexp.MustCompile(fmt.Sprintf("^%s$", strings.Join(doubles, ".*")))
	result := make([]*coordinator.LogStream, 0, len(streams))
	for _, stream := range streams {
		if stream.Purged {
			continue
		}
		if stream.StreamType != logpb.StreamType_TEXT {
			// Multistream viewing only supported for text streams.
			continue
		}
		if r.MatchString(stream.Name) {
			result = append(result, stream)
		}
	}
	return result
}
492521
func CheckLogLevel(level string) error {
	if !flogging.IsValidLevel(level) {
		return errors.Errorf("invalid log level provided - %s", level)
	}
	return nil
}
1008294
func (m *matcher) match(line string) *Template {
	tmpl := m.root.search(line)
	if tmpl != nil {
		return tmpl
	}
	return m.defaultTemplate
}
840593
func (l Logger) ShouldLog(path string) bool {
	for _, exc := range l.Exceptions {
		if Path(path).Matches(exc) {
			return false
		}
	}
	return true
}
596536
func oneLogLine(in []byte) []byte {
	return bytes.Replace(oneLogLineRegex.ReplaceAll(in, nil), []byte("\n"), []byte("\\n "), -1)
}