Skip to content

Support for %{env} variable in formatter. #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
fmtVerbShortfunc
fmtVerbCallpath
fmtVerbLevelColor
fmtVerbEnv

// Keep last, there are no match for these below.
fmtVerbUnknown
Expand All @@ -64,6 +65,7 @@ var fmtVerbs = []string{
"shortfunc",
"callpath",
"color",
"env",
}

const rfc3339Milli = "2006-01-02T15:04:05.999Z07:00"
Expand All @@ -84,6 +86,7 @@ var defaultVerbsLayout = []string{
"s",
"0",
"",
"s",
}

var (
Expand Down Expand Up @@ -154,6 +157,7 @@ type stringFormatter struct {
// The verbs:
//
// General:
// %{env} Environment
// %{id} Sequence number for log message (uint64).
// %{pid} Process id (int)
// %{time} Time when log occurred (time.Time)
Expand Down Expand Up @@ -306,6 +310,8 @@ func (f *stringFormatter) Format(calldepth int, r *Record, output io.Writer) err
case fmtVerbMessage:
v = r.Message()
break
case fmtVerbEnv:
v = os.Getenv("ENV")
case fmtVerbLongfile, fmtVerbShortfile:
_, file, line, ok := runtime.Caller(calldepth + 1)
if !ok {
Expand Down