Don't timestamp active log file (#11070)
* don't timestamp active log file * website: update log_file default value * changelog: add entry for #11070 * website: add upgrade instructions for log_file in v1.14 and v1.2.0
This commit is contained in:
parent
f87ae568d9
commit
104d29e808
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
agent: Don't timestamp active log file.
|
||||
```
|
|
@ -62,11 +62,8 @@ func (l *logFile) fileNamePattern() string {
|
|||
}
|
||||
|
||||
func (l *logFile) openNew() error {
|
||||
fileNamePattern := l.fileNamePattern()
|
||||
// New file name has the format : filename-timestamp.extension
|
||||
createTime := now()
|
||||
newfileName := fmt.Sprintf(fileNamePattern, strconv.FormatInt(createTime.UnixNano(), 10))
|
||||
newfilePath := filepath.Join(l.logPath, newfileName)
|
||||
newfilePath := filepath.Join(l.logPath, l.fileName)
|
||||
// Try creating a file. We truncate the file because we are the only authority to write the logs
|
||||
filePointer, err := os.OpenFile(newfilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640)
|
||||
if err != nil {
|
||||
|
@ -86,8 +83,18 @@ func (l *logFile) rotate() error {
|
|||
// Rotate if we hit the byte file limit or the time limit
|
||||
if (l.BytesWritten >= int64(l.MaxBytes) && (l.MaxBytes > 0)) || timeElapsed >= l.duration {
|
||||
l.FileInfo.Close()
|
||||
|
||||
// Move current log file to a timestamped file.
|
||||
rotateTime := now()
|
||||
rotatefileName := fmt.Sprintf(l.fileNamePattern(), strconv.FormatInt(rotateTime.UnixNano(), 10))
|
||||
oldPath := l.FileInfo.Name()
|
||||
newPath := filepath.Join(l.logPath, rotatefileName)
|
||||
if err := os.Rename(oldPath, newPath); err != nil {
|
||||
return fmt.Errorf("failed to rotate log files: %v", err)
|
||||
}
|
||||
|
||||
if err := l.pruneFiles(); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to prune log files: %v", err)
|
||||
}
|
||||
return l.openNew()
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ func TestLogFile_openNew(t *testing.T) {
|
|||
|
||||
_, err = ioutil.ReadFile(logFile.FileInfo.Name())
|
||||
require.NoError(err)
|
||||
|
||||
require.Equal(logFile.FileInfo.Name(), filepath.Join(tempDir, testFileName))
|
||||
}
|
||||
|
||||
func TestLogFile_byteRotation(t *testing.T) {
|
||||
|
|
|
@ -241,9 +241,9 @@ testing.
|
|||
- `log_json` `(bool: false)` - Output logs in a JSON format.
|
||||
|
||||
- `log_file` `(string: "")` - Specifies the path for logging. If the path
|
||||
does not includes a filename, the filename defaults to "nomad-{timestamp}.log".
|
||||
This setting can be combined with `log_rotate_bytes` and `log_rotate_duration`
|
||||
for a fine-grained log rotation control.
|
||||
does not includes a filename, the filename defaults to `nomad.log`. This
|
||||
setting can be combined with `log_rotate_bytes` and `log_rotate_duration` for
|
||||
a fine-grained log rotation control.
|
||||
|
||||
- `log_rotate_bytes` `(int: 0)` - Specifies the number of bytes that should be
|
||||
written to a log before it needs to be rotated. Unless specified, there is no
|
||||
|
|
|
@ -13,6 +13,15 @@ upgrade. However, specific versions of Nomad may have more details provided for
|
|||
their upgrades as a result of new features or changed behavior. This page is
|
||||
used to document those details separately from the standard upgrade flow.
|
||||
|
||||
## Nomad 1.1.4 and 1.2.0
|
||||
|
||||
#### Log file names
|
||||
|
||||
The [`log_file`] configuration option was not being fully respected, as the
|
||||
generated filename would include a timestamp. After upgrade, the active log
|
||||
file will always be the value defined in `log_file`, with timestamped files
|
||||
being created during log rotation.
|
||||
|
||||
## Nomad 1.0.9 and 1.1.3
|
||||
|
||||
#### Namespace in Job Run and Plan APIs
|
||||
|
@ -1173,3 +1182,4 @@ deleted and then Nomad 0.3.0 can be launched.
|
|||
[allow_caps_java]: /docs/drivers/java#allow_caps
|
||||
[cap_add_exec]: /docs/drivers/exec#cap_add
|
||||
[cap_drop_exec]: /docs/drivers/exec#cap_drop
|
||||
[`log_file`]: /docs/configuration#log_file
|
||||
|
|
Loading…
Reference in New Issue