backport of commit 1ffdd576bbcea1f32aa179934b63450808c022c4 (#18772)
Co-authored-by: James Rasell <jrasell@users.noreply.github.com>
This commit is contained in:
parent
fe612a4d18
commit
657c430e0b
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
agent: Added config option to enable file and line log detail
|
||||
```
|
|
@ -121,6 +121,7 @@ func (c *Command) readConfig() *Config {
|
|||
flags.StringVar(&cmdConfig.Datacenter, "dc", "", "")
|
||||
flags.StringVar(&cmdConfig.LogLevel, "log-level", "", "")
|
||||
flags.BoolVar(&cmdConfig.LogJson, "log-json", false, "")
|
||||
flags.BoolVar(&cmdConfig.LogIncludeLocation, "log-include-location", false, "")
|
||||
flags.StringVar(&cmdConfig.NodeName, "node", "", "")
|
||||
|
||||
// Consul options
|
||||
|
@ -734,10 +735,11 @@ func (c *Command) Run(args []string) int {
|
|||
|
||||
// Create logger
|
||||
logger := hclog.NewInterceptLogger(&hclog.LoggerOptions{
|
||||
Name: "agent",
|
||||
Level: hclog.LevelFromString(config.LogLevel),
|
||||
Output: logOutput,
|
||||
JSONFormat: config.LogJson,
|
||||
Name: "agent",
|
||||
Level: hclog.LevelFromString(config.LogLevel),
|
||||
Output: logOutput,
|
||||
JSONFormat: config.LogJson,
|
||||
IncludeLocation: config.LogIncludeLocation,
|
||||
})
|
||||
|
||||
// Wrap log messages emitted with the 'log' package.
|
||||
|
@ -1346,6 +1348,9 @@ General Options (clients and servers):
|
|||
-log-json
|
||||
Output logs in a JSON format. The default is false.
|
||||
|
||||
-log-include-location
|
||||
Include file and line information in each log line. The default is false.
|
||||
|
||||
-node=<name>
|
||||
The name of the local agent. This name is used to identify the node
|
||||
in the cluster. The name must be unique per region. The default is
|
||||
|
|
|
@ -68,6 +68,11 @@ type Config struct {
|
|||
// LogFile enables logging to a file
|
||||
LogFile string `hcl:"log_file"`
|
||||
|
||||
// LogIncludeLocation dictates whether the logger includes file and line
|
||||
// information on each log line. This is useful for Nomad development and
|
||||
// debugging.
|
||||
LogIncludeLocation bool `hcl:"log_include_location"`
|
||||
|
||||
// LogRotateDuration is the time period that logs should be rotated in
|
||||
LogRotateDuration string `hcl:"log_rotate_duration"`
|
||||
|
||||
|
@ -1410,6 +1415,9 @@ func (c *Config) Merge(b *Config) *Config {
|
|||
if b.LogFile != "" {
|
||||
result.LogFile = b.LogFile
|
||||
}
|
||||
if b.LogIncludeLocation {
|
||||
result.LogIncludeLocation = true
|
||||
}
|
||||
if b.LogRotateDuration != "" {
|
||||
result.LogRotateDuration = b.LogRotateDuration
|
||||
}
|
||||
|
|
|
@ -18,16 +18,17 @@ import (
|
|||
)
|
||||
|
||||
var basicConfig = &Config{
|
||||
Region: "foobar",
|
||||
Datacenter: "dc2",
|
||||
NodeName: "my-web",
|
||||
DataDir: "/tmp/nomad",
|
||||
PluginDir: "/tmp/nomad-plugins",
|
||||
LogFile: "/var/log/nomad.log",
|
||||
LogLevel: "ERR",
|
||||
LogJson: true,
|
||||
BindAddr: "192.168.0.1",
|
||||
EnableDebug: true,
|
||||
Region: "foobar",
|
||||
Datacenter: "dc2",
|
||||
NodeName: "my-web",
|
||||
DataDir: "/tmp/nomad",
|
||||
PluginDir: "/tmp/nomad-plugins",
|
||||
LogFile: "/var/log/nomad.log",
|
||||
LogLevel: "ERR",
|
||||
LogIncludeLocation: true,
|
||||
LogJson: true,
|
||||
BindAddr: "192.168.0.1",
|
||||
EnableDebug: true,
|
||||
Ports: &Ports{
|
||||
HTTP: 1234,
|
||||
RPC: 2345,
|
||||
|
|
|
@ -57,6 +57,7 @@ func TestConfig_Merge(t *testing.T) {
|
|||
DataDir: "/tmp/dir1",
|
||||
PluginDir: "/tmp/pluginDir1",
|
||||
LogLevel: "INFO",
|
||||
LogIncludeLocation: false,
|
||||
LogJson: false,
|
||||
EnableDebug: false,
|
||||
LeaveOnInt: false,
|
||||
|
@ -244,6 +245,7 @@ func TestConfig_Merge(t *testing.T) {
|
|||
DataDir: "/tmp/dir2",
|
||||
PluginDir: "/tmp/pluginDir2",
|
||||
LogLevel: "DEBUG",
|
||||
LogIncludeLocation: true,
|
||||
LogJson: true,
|
||||
EnableDebug: true,
|
||||
LeaveOnInt: true,
|
||||
|
|
|
@ -18,6 +18,8 @@ log_json = true
|
|||
|
||||
log_file = "/var/log/nomad.log"
|
||||
|
||||
log_include_location = true
|
||||
|
||||
bind_addr = "192.168.0.1"
|
||||
|
||||
enable_debug = true
|
||||
|
|
|
@ -181,6 +181,7 @@
|
|||
"leave_on_interrupt": true,
|
||||
"leave_on_terminate": true,
|
||||
"log_file": "/var/log/nomad.log",
|
||||
"log_include_location": true,
|
||||
"log_json": true,
|
||||
"log_level": "ERR",
|
||||
"name": "my-web",
|
||||
|
|
|
@ -109,6 +109,8 @@ via CLI arguments. The `agent` command accepts the following arguments:
|
|||
|
||||
- `-log-level=<level>`: Equivalent to the [log_level] config option.
|
||||
|
||||
- `-log-include-location`: Equivalent to the [log_include_location] config option.
|
||||
|
||||
- `-log-json`: Equivalent to the [log_json] config option.
|
||||
|
||||
- `-meta=<key=value>`: Equivalent to the Client [meta] config option.
|
||||
|
@ -202,6 +204,7 @@ via CLI arguments. The `agent` command accepts the following arguments:
|
|||
[enabled]: /nomad/docs/configuration/acl#enabled
|
||||
[encryption overview]: /nomad/tutorials/transport-security/security-gossip-encryption
|
||||
[key_file]: /nomad/docs/configuration/consul#key_file
|
||||
[log_include_location]: /nomad/docs/configuration#log_include_location
|
||||
[log_json]: /nomad/docs/configuration#log_json
|
||||
[log_level]: /nomad/docs/configuration#log_level
|
||||
[meta]: /nomad/docs/configuration/client#meta
|
||||
|
|
|
@ -248,6 +248,9 @@ testing.
|
|||
agent will output. Valid log levels include `WARN`, `INFO`, or `DEBUG` in
|
||||
increasing order of verbosity.
|
||||
|
||||
- `log_include_location` `(bool: false)` - Include file and line information in
|
||||
each log line.
|
||||
|
||||
- `log_json` `(bool: false)` - Output logs in a JSON format.
|
||||
|
||||
- `log_file` `(string: "")` - Specifies the path for logging. If the path
|
||||
|
|
Loading…
Reference in New Issue