Skip to content

Commit

Permalink
Merge pull request cihub#51 from jmassara/master
Browse files Browse the repository at this point in the history
Add support for UTC date/time formats.
  • Loading branch information
goodsign committed May 14, 2014
2 parents d18b81e + 5080c39 commit 2b0831a
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ var formatterFuncs = map[string]FormatterFunc{
"FuncShort": FormatterFunctionShort,
"Line": formatterLine,
"Time": formatterTime,
"UTCTime": formatterUTCTime,
"Ns": formatterNs,
"UTCNs": formatterUTCNs,
"n": formattern,
"t": formattert,
}

var formatterFuncsParameterized = map[string]FormatterFuncCreator{
"Date": createDateTimeFormatterFunc,
"EscM": createANSIEscapeFunc,
"Date": createDateTimeFormatterFunc,
"UTCDate": createUTCDateTimeFormatterFunc,
"EscM": createANSIEscapeFunc,
}

func errorAliasReserved(name string) error {
Expand Down Expand Up @@ -405,10 +408,18 @@ func formatterTime(message string, level LogLevel, context LogContextInterface)
return context.CallTime().Format(TimeFormat)
}

func formatterUTCTime(message string, level LogLevel, context LogContextInterface) interface{} {
return context.CallTime().UTC().Format(TimeFormat)
}

func formatterNs(message string, level LogLevel, context LogContextInterface) interface{} {
return context.CallTime().UnixNano()
}

func formatterUTCNs(message string, level LogLevel, context LogContextInterface) interface{} {
return context.CallTime().UTC().UnixNano()
}

func formattern(message string, level LogLevel, context LogContextInterface) interface{} {
return "\n"
}
Expand All @@ -427,6 +438,16 @@ func createDateTimeFormatterFunc(dateTimeFormat string) FormatterFunc {
}
}

func createUTCDateTimeFormatterFunc(dateTimeFormat string) FormatterFunc {
format := dateTimeFormat
if format == "" {
format = DateDefaultFormat
}
return func(message string, level LogLevel, context LogContextInterface) interface{} {
return time.Now().UTC().Format(format)
}
}

func createANSIEscapeFunc(escapeCodeString string) FormatterFunc {
return func(message string, level LogLevel, context LogContextInterface) interface{} {
if len(escapeCodeString) == 0 {
Expand Down

0 comments on commit 2b0831a

Please sign in to comment.