Skip to content

Commit 6fb31e8

Browse files
committed
Merge branch 'devel' of https://github.com/DeRuina/timberjack into devel
2 parents b70beef + f19202c commit 6fb31e8

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.3.6](https://github.com/DeRuina/timberjack/compare/v1.3.5...v1.3.6) (2025-09-16)
4+
5+
### Features
6+
7+
* Append the backupTimeFormat to the end of file name ([#40](https://github.com/DeRuina/timberjack/issues/37)) ([15c6d81](https://github.com/DeRuina/timberjack/commit/15c6d813214c9c7f1372af55f9b705d9d2a3a88e))
8+
9+
310
## [1.3.5](https://github.com/DeRuina/timberjack/compare/v1.3.4...v1.3.5) (2025-08-19)
411

512
### Features

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type Logger struct {
118118
// Back-compat shim for old configs; will be removed in v2.
119119
Compress bool
120120

121+
121122
RotationInterval time.Duration // Rotate after this duration (if > 0)
122123
RotateAtMinutes []int // Specific minutes within an hour (0–59) to trigger rotation
123124
RotateAt []string // Specific daily times (HH:MM, 24-hour) to trigger rotation
@@ -152,7 +153,9 @@ For example:
152153
```
153154

154155
If you prefer the extension to stay attached to the live name (better shell TAB completion),
156+
155157
set `AppendTimeAfterExt: true`:
158+
156159
```
157160
<name>.log-<timestamp>-<reason>
158161
```

timberjack.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ type Logger struct {
172172
// true: <name>.log-<timestamp>-<reason>
173173
AppendTimeAfterExt bool `json:"appendTimeAfterExt" yaml:"appendTimeAfterExt"`
174174

175+
175176
// Internal fields
176177
size int64 // current size of the log file
177178
file *os.File // current log file
@@ -646,6 +647,7 @@ func (l *Logger) openNew(reasonForBackup string) error {
646647
}
647648

648649
newname := backupName(name, l.LocalTime, reasonForBackup, rotationTimeForBackup, l.BackupTimeFormat, l.AppendTimeAfterExt)
650+
649651
if errRename := osRename(name, newname); errRename != nil {
650652
return fmt.Errorf("can't rename log file: %s", errRename)
651653
}
@@ -692,6 +694,7 @@ func (l *Logger) shouldTimeRotate() bool {
692694
// ("time" or "size") between the filename prefix and the extension.
693695
// It uses the local time if requested (otherwise UTC).
694696
func backupName(name string, local bool, reason string, t time.Time, fileTimeFormat string, appendTimeAfterExt bool) string {
697+
695698
dir := filepath.Dir(name)
696699
filename := filepath.Base(name)
697700
ext := filepath.Ext(filename)
@@ -703,6 +706,7 @@ func backupName(name string, local bool, reason string, t time.Time, fileTimeFor
703706
}
704707
// Format the timestamp for the backup file.
705708
timestamp := t.In(currentLoc).Format(fileTimeFormat)
709+
706710
if appendTimeAfterExt {
707711
// <name><ext>-<ts>-<reason>
708712
// e.g. httpd.log-2025-01-01T00-00-00.000-size
@@ -963,6 +967,7 @@ func (l *Logger) timeFromName(filename, prefix, ext string) (time.Time, error) {
963967
}
964968

965969
if !l.AppendTimeAfterExt {
970+
966971
// Keep legacy behavior for error messages to satisfy existing tests
967972
if !strings.HasPrefix(filename, prefix) {
968973
return time.Time{}, errors.New("mismatched prefix")
@@ -994,6 +999,7 @@ func (l *Logger) timeFromName(filename, prefix, ext string) (time.Time, error) {
994999

9951000
// nameNoComp = "<base>-<timestamp>-<reason>"
9961001
trimmed := nameNoComp[len(base)+1:]
1002+
9971003
lastHyphenIdx := strings.LastIndex(trimmed, "-")
9981004
if lastHyphenIdx == -1 {
9991005
return time.Time{}, fmt.Errorf("malformed backup filename: %q", filename)

0 commit comments

Comments
 (0)