Skip to content
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

Allow to log function name and location #130

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
metricsAddress string
gracePeriod time.Duration
logFormat string
logCaller bool
)

func init() {
Expand All @@ -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() {
Expand All @@ -85,6 +87,8 @@ func main() {
log.SetFormatter(&log.JSONFormatter{})
}

log.SetReportCaller(logCaller)

log.WithFields(log.Fields{
"labels": labelString,
"annotations": annString,
Expand Down