summaryrefslogtreecommitdiff
path: root/internal/logging/const.go
blob: 47e11be08505cc7a6870ab2ff933cae4e5675348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package logging

import (
	"regexp"
	"sync"

	"github.com/sirupsen/logrus"
)

// Log Format values.
const (
	FormatText = "text"
	FormatJSON = "json"
)

type LogLevel string

// Log Level values.
const (
	LevelTrace = "trace"
	LevelDebug = "debug"
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"
)

func (l LogLevel) Level() logrus.Level {
	switch l {
	case LevelError:
		return logrus.ErrorLevel
	case LevelWarn:
		return logrus.WarnLevel
	case LevelInfo:
		return logrus.InfoLevel
	case LevelDebug:
		return logrus.DebugLevel
	case LevelTrace:
		return logrus.TraceLevel
	default:
		return logrus.InfoLevel
	}
}

// Field names.
const (
	FieldRemoteIP   = "remote_ip"
	FieldMethod     = "method"
	FieldPath       = "path"
	FieldPathRaw    = "path_raw"
	FieldStatusCode = "status_code"
)

var (
	stacktrace       sync.Once
	reFormatFilePath = regexp.MustCompile(`(%d|\{datetime(:([^}]+))?})`)
	lf               *File
)