summaryrefslogtreecommitdiff
path: root/internal/logging/util.go
blob: 451c307987ad34ce43aaa95cb13507ca452dacda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package logging

import (
	"strings"
	"time"
)

// FormatFilePath formats a file path with the given time.
func FormatFilePath(in string, now time.Time) (out string) {
	matches := reFormatFilePath.FindStringSubmatch(in)

	if len(matches) == 0 {
		return in
	}

	layout := time.RFC3339

	if len(matches[3]) != 0 {
		layout = matches[3]
	}

	return strings.Replace(in, matches[0], now.Format(layout), 1)
}