logs

package
v0.60.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2024 License: BSD-2-Clause, BSD-3-Clause, PostgreSQL Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const LogPrefixAmazonRds string = "%t:%r:%u@%d:[%p]:"
View Source
const LogPrefixAzure string = "%t-%c-"
View Source
const LogPrefixCustom1 string = "%m [%p][%v] : [%l-1] %q[app=%a] "
View Source
const LogPrefixCustom10 string = "%m [%p]: [%l-1] db=%d,user=%u "
View Source
const LogPrefixCustom11 string = "pid=%p,user=%u,db=%d,app=%a,client=%h "
View Source
const LogPrefixCustom12 string = "user=%u,db=%d,app=%a,client=%h "
View Source
const LogPrefixCustom13 string = "%p-%s-%c-%l-%h-%u-%d-%m "
View Source
const LogPrefixCustom14 string = "%m [%p][%b][%v][%x] %q[user=%u,db=%d,app=%a] "
View Source
const LogPrefixCustom15 string = "%m [%p] %q%u@%d "
View Source
const LogPrefixCustom16 string = "%t [%p] %q%u@%d %h "
View Source
const LogPrefixCustom2 string = "%t [%p-%l] %q%u@%d "
View Source
const LogPrefixCustom3 string = "%m [%p] %q[user=%u,db=%d,app=%a] "
View Source
const LogPrefixCustom4 string = "%m [%p] %q[user=%u,db=%d,app=%a,host=%h] "
View Source
const LogPrefixCustom5 string = "%t [%p]: [%l-1] user=%u,db=%d - PG-%e "
View Source
const LogPrefixCustom6 string = "%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h "
View Source
const LogPrefixCustom7 string = "%t [%p]: [%l-1] [trx_id=%x] user=%u,db=%d "
View Source
const LogPrefixCustom8 string = "[%p]: [%l-1] db=%d,user=%u "
View Source
const LogPrefixCustom9 string = "%m %r %u %a [%c] [%p] "
View Source
const LogPrefixEmpty string = ""
View Source
const LogPrefixHeroku1 string = " sql_error_code = %e "
View Source
const LogPrefixHeroku2 string = `` /* 186-byte string literal not displayed */
View Source
const LogPrefixHerokuHobbyTier string = " database = %d connection_source = %r sql_error_code = %e "

Used only to recognize the Heroku hobby tier log_line_prefix to give a warning (logs are not supported on hobby tier) and avoid errors during prefix check; logs with this prefix are never actually received

View Source
const LogPrefixRecommended = LogPrefixCustom3
View Source
const LogPrefixSimple string = "%m [%p] "
View Source
const MinSupportedLogMinDurationStatement = 10

Variables

View Source
var AppInsideBracketsRegexp = `(\[unknown\]|[^,\]]*)` // %a
View Source
var DbRegexp = `(\S*)` // %d
View Source
var EscapeMatchers = map[rune]PrefixEscape{

	'a': {
		Regexp: `.+?`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			if value == "[unknown]" {
				return
			}
			logLine.Application = value
		},
		Optional: true,
	},

	'u': {
		Regexp: `.+?`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			if value == "[unknown]" {
				return
			}
			logLine.Username = value
		},
		Optional: true,
	},

	'd': {
		Regexp: `.+?`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			if value == "[unknown]" {
				return
			}
			logLine.Database = value
		},
		Optional: true,
	},

	'r': {
		Regexp:   `[a-zA-Z0-9:.-]+\(\d{1,5}\)|\[local\]`,
		Optional: true,
	},

	'h': {
		Regexp:   `[a-zA-Z0-9:.-]+|\[local\]`,
		Optional: true,
	},

	'b': {
		Regexp: `[a-z ]+`,
	},

	'p': {
		Regexp: `\d+`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			intVal, _ := strconv.ParseInt(value, 10, 32)
			logLine.BackendPid = int32(intVal)
		},
	},

	'P': {
		Regexp:   `\d+`,
		Optional: true,
	},

	't': {
		Regexp: `\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (?:[A-Z]{1,4}|[+-]\d+)`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			logLine.OccurredAt = parser.GetOccurredAt(value)
		},
	},

	'm': {
		Regexp: `\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} (?:[A-Z]{1,4}|[+-]\d+)`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			logLine.OccurredAt = parser.GetOccurredAt(value)
		},
	},

	'n': {
		Regexp: `\d+\.\d+`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			tsparts := strings.SplitN(value, ".", 2)
			seconds, _ := strconv.ParseInt(tsparts[0], 10, 64)
			millis, _ := strconv.ParseInt(tsparts[1], 10, 64)
			logLine.OccurredAt = time.Unix(seconds, millis*1_000_000)
		},
	},

	'i': {
		Regexp:   `[A-Z_ ]+`,
		Optional: true,
	},

	'e': {
		Regexp: `[0-9A-Z]{5}`,
	},

	'c': {
		Regexp:   `[0-9a-f]{1,8}\.[0-9a-f]{1,8}`,
		Optional: true,
	},

	'l': {
		Regexp: `\d+`,
		ApplyValue: func(value string, logLine *state.LogLine, parser *LogParser) {
			intVal, _ := strconv.ParseInt(value, 10, 32)
			logLine.LogLineNumber = int32(intVal)
		},
	},

	's': {
		Regexp: `\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (?:[A-Z]{1,4}|[+-]\d+)`,
	},

	'v': {
		Regexp:   `\d+\/\d+`,
		Optional: true,
	},

	'x': {
		Regexp:   `\d+`,
		Optional: true,
	},

	'Q': {
		Regexp: `-?\d+`,
	},
}

This is a map of the various log_line_prefix format strings; see https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-LINE-PREFIX not included: %q and %%, which are easier to handle by special-casing

View Source
var HerokuPostgresDebugRegexp = regexp.MustCompile(`^(\w+ \d+ \d+:\d+:\d+ \w+ app\[postgres\] \w+ )?\[(\w+)\] \[\d+-\d+\] (.+)`)
View Source
var LevelAndContentRegexp = `(\w+):\s+(.*\n?)$`
View Source
var LogPrefixNoTimestampUserDatabaseAppRegexp = regexp.MustCompile(`(?s)^\[user=` + UserRegexp + `,db=` + DbRegexp + `,app=` + AppInsideBracketsRegexp + `\] ` + LevelAndContentRegexp)
View Source
var PidRegexp = `(\d+)` // %p
View Source
var RsyslogHostnameRegxp = `(\S+)`
View Source
var RsyslogLevelAndContentRegexp = `(?:(\w+):\s+)?(.*\n?)$`
View Source
var RsyslogProcessNameRegexp = `(\w+)`
View Source
var RsyslogTimeRegexp = `(\w+\s+\d+ \d{2}:\d{2}:\d{2})`
View Source
var SyslogSequenceAndSplitRegexp = `(\[[\d-]+\])?`
View Source
var UserRegexp = `(\S*)` // %u

Functions

func AnalyzeBackendLogLines

func AnalyzeBackendLogLines(logLines []state.LogLine) (logLinesOut []state.LogLine, samples []state.PostgresQuerySample)

func AnalyzeLogLines

func AnalyzeLogLines(logLinesIn []state.LogLine) (logLinesOut []state.LogLine, samples []state.PostgresQuerySample)

func ParseAndAnalyzeBuffer

func ParseAndAnalyzeBuffer(logStream LineReader, linesNewerThan time.Time, server *state.Server) ([]state.LogLine, []state.PostgresQuerySample)

func PrintDebugInfo

func PrintDebugInfo(logLines []state.LogLine, samples []state.PostgresQuerySample)

func PrintDebugLogLines added in v0.49.0

func PrintDebugLogLines(logLines []state.LogLine, classifications map[pganalyze_collector.LogLineInformation_LogClassification]bool)

func ReplaceSecrets

func ReplaceSecrets(logLines []state.LogLine, filterLogSecret []state.LogSecretKind)

func SyncLogParser added in v0.58.0

func SyncLogParser(server *state.Server, settings []state.PostgresSetting)

func ValidateLogCollectionConfig

func ValidateLogCollectionConfig(server *state.Server, settings []state.PostgresSetting) (bool, bool, bool, string)

Types

type LineReader added in v0.49.0

type LineReader interface {
	ReadString(delim byte) (string, error)
}

type LogParser added in v0.58.0

type LogParser struct {
	// contains filtered or unexported fields
}

func NewLogParser added in v0.58.0

func NewLogParser(prefix string, tz *time.Location, isSyslog bool) *LogParser

func (*LogParser) GetOccurredAt added in v0.58.0

func (lp *LogParser) GetOccurredAt(timePart string) time.Time

func (*LogParser) GetPrefixAndContent added in v0.58.0

func (lp *LogParser) GetPrefixAndContent(line string) (prefix string, content string, ok bool)

func (*LogParser) Matches added in v0.58.0

func (lp *LogParser) Matches(prefix string, tz *time.Location, isSyslog bool) bool

func (*LogParser) ParseLine added in v0.58.0

func (lp *LogParser) ParseLine(line string) (logLine state.LogLine, ok bool)

func (*LogParser) ValidatePrefix added in v0.58.0

func (lp *LogParser) ValidatePrefix() error

type MaybeHerokuLogReader added in v0.49.0

type MaybeHerokuLogReader struct {
	LineReader
}

func NewMaybeHerokuLogReader added in v0.49.0

func NewMaybeHerokuLogReader(r io.Reader) *MaybeHerokuLogReader

func (*MaybeHerokuLogReader) ReadString added in v0.49.0

func (lr *MaybeHerokuLogReader) ReadString(delim byte) (string, error)

type PrefixEscape added in v0.58.0

type PrefixEscape struct {
	Regexp     string
	ApplyValue func(value string, logLine *state.LogLine, parser *LogParser)
	// Indicates a value may not always be present for this escape (e.g., when logging from a non-backend process)
	Optional bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL