From 132851f345e5bf7521379291459f2da998990d2d Mon Sep 17 00:00:00 2001 From: Martin Linkhorst Date: Thu, 18 Jul 2019 14:11:22 +0200 Subject: [PATCH] feat: allow to log function name and location --- README.md | 2 ++ main.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 9e2ce9ae..a90a9f32 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,8 @@ Use `UTC`, `Local` or pick a timezone name from the [(IANA) tz database](https:/ | `--timezone` | timezone from tz database, e.g. "America/New_York", "UTC" or "Local" | (UTC) | | `--minimum-age` | Minimum age to filter pods by | 0s (matches every pod) | | `--dry-run` | don't kill pods, only log what would have been done | true | +| `--log-format` | specify the format of the log messages. Options are text and json | text | +| `--log-caller` | include the calling function name and location in the log messages | false | ## Related work diff --git a/main.go b/main.go index 07000d6b..e9c48f3c 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,7 @@ var ( metricsAddress string gracePeriod time.Duration logFormat string + logCaller bool ) func init() { @@ -71,6 +72,7 @@ func init() { kingpin.Flag("metrics-address", "Listening address for metrics handler").Default(":8080").StringVar(&metricsAddress) kingpin.Flag("grace-period", "Grace period to terminate Pods. Negative values will use the Pod's grace period.").Default("-1s").DurationVar(&gracePeriod) kingpin.Flag("log-format", "Specify the format of the log messages. Options are text and json. Defaults to text.").Default("text").EnumVar(&logFormat, "text", "json") + kingpin.Flag("log-caller", "Include the calling function name and location in the log messages.").BoolVar(&logCaller) } func main() { @@ -85,6 +87,8 @@ func main() { log.SetFormatter(&log.JSONFormatter{}) } + log.SetReportCaller(logCaller) + log.WithFields(log.Fields{ "labels": labelString, "annotations": annString,