mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
config: Add required configuration for logging to a file
This commit is contained in:
@@ -57,6 +57,18 @@ type Config struct {
|
||||
// LogJson enables log output in a JSON format
|
||||
LogJson bool `hcl:"log_json"`
|
||||
|
||||
// LogFile enables logging to a file
|
||||
LogFile string `hcl:"log_file"`
|
||||
|
||||
// LogRotateDuration is the time period that logs should be rotated in
|
||||
LogRotateDuration string `hcl:"log_rotate_duration"`
|
||||
|
||||
// LogRotateBytes is the max number of bytes that should be written to a file
|
||||
LogRotateBytes int `hcl:"log_rotate_bytes"`
|
||||
|
||||
// LogRotateMaxFiles is the max number of log files to keep
|
||||
LogRotateMaxFiles int `hcl:"log_rotate_max_files"`
|
||||
|
||||
// BindAddr is the address on which all of nomad's services will
|
||||
// be bound. If not specified, this defaults to 127.0.0.1.
|
||||
BindAddr string `hcl:"bind_addr"`
|
||||
@@ -898,6 +910,18 @@ func (c *Config) Merge(b *Config) *Config {
|
||||
if b.LogJson {
|
||||
result.LogJson = true
|
||||
}
|
||||
if b.LogFile != "" {
|
||||
result.LogFile = b.LogFile
|
||||
}
|
||||
if b.LogRotateDuration != "" {
|
||||
result.LogRotateDuration = b.LogRotateDuration
|
||||
}
|
||||
if b.LogRotateBytes != 0 {
|
||||
result.LogRotateBytes = b.LogRotateBytes
|
||||
}
|
||||
if b.LogRotateMaxFiles != 0 {
|
||||
result.LogRotateMaxFiles = b.LogRotateMaxFiles
|
||||
}
|
||||
if b.BindAddr != "" {
|
||||
result.BindAddr = b.BindAddr
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ var basicConfig = &Config{
|
||||
NodeName: "my-web",
|
||||
DataDir: "/tmp/nomad",
|
||||
PluginDir: "/tmp/nomad-plugins",
|
||||
LogFile: "/var/log/nomad.log",
|
||||
LogLevel: "ERR",
|
||||
LogJson: true,
|
||||
BindAddr: "192.168.0.1",
|
||||
@@ -409,14 +410,10 @@ func TestConfig_Parse(t *testing.T) {
|
||||
t.Run(tc.File, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
path, err := filepath.Abs(filepath.Join("./testdata", tc.File))
|
||||
if err != nil {
|
||||
t.Fatalf("file: %s\n\n%s", tc.File, err)
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
actual, err := ParseConfigFile(path)
|
||||
if (err != nil) != tc.Err {
|
||||
t.Fatalf("file: %s\n\n%s", tc.File, err)
|
||||
}
|
||||
require.NoError(err)
|
||||
|
||||
// ParseConfig used to re-merge defaults for these three objects,
|
||||
// despite them already being merged in LoadConfig. The test structs
|
||||
|
||||
2
command/agent/testdata/basic.hcl
vendored
2
command/agent/testdata/basic.hcl
vendored
@@ -13,6 +13,8 @@ log_level = "ERR"
|
||||
|
||||
log_json = true
|
||||
|
||||
log_file = "/var/log/nomad.log"
|
||||
|
||||
bind_addr = "192.168.0.1"
|
||||
|
||||
enable_debug = true
|
||||
|
||||
1
command/agent/testdata/basic.json
vendored
1
command/agent/testdata/basic.json
vendored
@@ -143,6 +143,7 @@
|
||||
],
|
||||
"leave_on_interrupt": true,
|
||||
"leave_on_terminate": true,
|
||||
"log_file": "/var/log/nomad.log",
|
||||
"log_json": true,
|
||||
"log_level": "ERR",
|
||||
"name": "my-web",
|
||||
|
||||
Reference in New Issue
Block a user