Starting with Java agent version 7.6.0, support for logs in context has been added to the agent, making it easy to use for supported logging frameworks. For tips on using the Java agent for logs in context, see Java logs in context.
Changing these settings in your local agent configuration file happens dynamically and doesn't require a restart of the agent for those changes to take effect. An example configuration:
application_logging:
enabled:true
forwarding:
enabled:true
max_samples_stored:10000
labels:
enabled:false
exclude:
context_data:
enabled:false
include:
exclude:
log_level_denylist: debug
metrics:
enabled:true
local_decorating:
enabled:false
Set the logs in context configuration in the application_logging section. This can be overridden with a newrelic.config.application_logging prefixed system property. The only option available is:
Type
Boolean
Default
true
Set to true to enable the core logs in context feature. When enabled, additional logging framework instrumentation is enabled, whether or not logs are decorated or sent to New Relic.
重要
Agent releases 7.7.0 and higher has this feature enabled in the agent configuration file by default.
Set to false to completely disable this feature, including the collection of log metrics.
Log forwarding
If you're using a supported logging framework and want to use the agent to send your application logs to New Relic, you can control that through settings under the forwarding section. These settings can be overridden by the newrelic.config.application_logging.forwarding prefixed system property. Options available are:
Type
Boolean
Default
true
Enables the sending of application logs to New Relic.
重要
Agent releases 7.7.0 and higher have this feature enabled in the agent configuration file by default.
Using the log forwarding feature will increase your data ingest, which may affect your billing. For more information, see our documentation about tracking your data ingest.
If you have an existing log forwarding solution and are updating your agent to use automatic logs in context, be sure to disable your old log forwarder. Otherwise, your app will be sending double log lines. Depending on your account, this could result in double billing. For more information, follow the procedures to disable your specific log forwarder.
Set this to true to have your decorated logs sent to New Relic.
Set this to false if you do not want your decorated logs sent to New Relic.
Type
Integer
Default
10000
A positive integer specifying the maximum number of logs lines per minute to send.
Set this to 0 to effectively disable the sending of logs.
重要
This controls the number of logs sent per minute. Setting max_samples_stored to 0 - or any value less than 12 - does not disable the feature itself, though it does result in no log lines being sent to New Relic.
Set this to a lower value to reduce the amount of log lines sent (may cause log sampling). Set this to a higher value to send more log lines.
Each log receives the same priority as its associated transaction. Logs that occur outside of a transaction will receive a random priority. Some logs may not be included because they are limited by max_samples_stored. For example, if logging max_samples_stored is set to 10,000 and transaction 1 has 10,000 log entries, only log entries for transaction 1 will be recorded. If transaction 1 has less than 10,000 logs you receive all logs for transaction 1. If there is still space, you receive all the logs for transaction 2, and so on.
If after all the logs for sampled transactions are recorded, and they haven't reached the limit in max_samples_stored, then log messages for transactions that were not in our sampling are sent. If there are any left, log messages outside of transactions are recorded.
Log labels (tags)
The Java agent supports adding custom labels (tags) to agent-forwarded logs. Labels are sourced from the labels section at the top level of the agent configuration. This feature can be enabled within the labels section, nested under the forwarding section. You can override these settings using the newrelic.config.application_logging.forwarding.labels prefixed system property. Available options include:
Type
Boolean
Default
false
Toggles whether the agent will add labels to logs that are forwarded to New Relic.
Type
List of strings
Default
(none)
A case-insensitive list of label names to exclude when labels for logs are enabled. This attribute does not support wildcards or regex.
重要
When adding labels as attributes, the agent prefixes the keys with tags.. This prefix is NOT included when matching against the exclude filtering rules.
Log context data
The Java agent can capture context data (Mapped Diagnostic Context in logback/slf4j, ThreadContext in log4j2) and add its contents as attributes in the logs forwarded to New Relic. You can control that through settings in the context_data section, nested under the forwarding section. These settings can be overridden by the newrelic.config.application_logging.forwarding.context_data prefixed system property. Options available are:
Type
Boolean
Default
false
Set this to true sending of context data as log attributes to New Relic.
Set this to false if you do not want context data in the logs sent to New Relic.
Type
List of strings
Default
(none)
If context_data is enabled for log forwarding, all attribute keys found in this list will be sent to New Relic in log records. If this list is empty, then all attributes will be sent.
Type
List of strings
Default
(none)
If context_data is enabled for log forwarding, all attribute keys found in this list will NOT be sent to New Relic in log records.
The include and exclude list follow the rules Exclude overrides include, More specific rules take priority, Keys are case-sensitive and Use an asterisk for wildcards defined in Attribute rules.
Log Level Denylist
The Java agent can omit specific log levels from generating LogEvents that get forwarded to New Relic.
You can control that through the log_level_denylist config option, nested under the forwarding section. This setting allows you to define a comma separated list of strings representing log levels (e.g. log_level_denylist: "info, debug") that should not have log events forwarded. Log level names are case-insensitive but otherwise must be an exact match. These settings can be overridden by the newrelic.config.application_logging.forwarding.log_level_denylist prefixed system property. The only available option is:
Type
List of strings
Default
(none)
Log metrics
In addition to allowing you to decorate and send individual log lines, the Java agent can capture logging metric data. You can find this data in the logs chart in the New Relic UI. You can configure log metrics settings in the metrics section. You can override these settings with the newrelic.config.application_logging.metrics prefixed system property. The only available option is:
Type
Boolean
Default
true
Enables the capture of metrics information about your logs and log levels, which is displayed in a chart on the APM Summary page.
Leave this set to true to allow the agent to capture metric information about your logs.
Set this to false to disable this feature.
重要
If you disable the collection of log metrics, the log chart on the summary page will appear blank.
Log decorating
You can configure the log decorating settings in the local_decorating section. You can use this to control how local log lines are decorated. You can override these settings with a newrelic.config.application_logging.local_decorating prefixed system property. The only option available is:
Type
Boolean
Default
false
This controls whether locally stored log lines are decorated or not. This is independent of whether log forwarding is enabled or not and is used to support customers that want to use a separate log forwarding solution.
Set this to true to cause the agent to add logs in context linking metadata to log lines stored locally by supported frameworks.
重要
Enabling local log decorating will add linking metadata to your application log files, resulting in an increase in disk storage. Disable this feature if this is unacceptable.
It is not necessary to use local log decorating when log forwarding is enabled. Doing so will cause linking metadata to be added to your log messages unnecessarily, which may be visually distracting.
Set this to false to turn off the local decorating feature. This will not impact the decorating of log lines being sent to New Relic.
Logging configuration
These are part of the general configuration variables. They are broken out here because they are frequently tweaked for debugging.
Some of the logging configuration variables are dynamic and do not need a host restart for them to take effect. For instance, if log files are growing too quickly, log_level can be set to a less verbose setting to reduce the reporting rate.
Here is the order of precedence and explanation for configuration variables affecting log rotation.
If log_daily is true:
A log_limit_in_kbytes value greater than zero will result in a composite triggering policy, where logs will roll once per day or when the defined size is reached, retaining up to log_file_count files
A log_limit_in_kbytes value of zero will result in logs rolling once per day retaining up to log_file_count files
If log_daily is false and log_limit_in_kbytes > 0, a sized based policy will be configured, where logs will roll when the defined size is reached, retaining up to log_file_count files
If log_daily is false and log_limit_in_kbytes = 0, no log file rolling logic will be configured
Depending on the growth rate, it is possible for the log file size to exceed the configured value by a small amount.
Type
Boolean
Default
false
Set to true to roll the logs daily.
Type
Integer
Default
1
The maximum number of log files to keep when using log rotation.
Type
String
Default
newrelic_agent.log
The unqualified log file name or the string STDOUT which will log to standard out.
Type
String
Default
logs subdirectory where newrelic.jar is located
The log file path.
ヒント
If log_file_path is specified, the directory must already exist. If the default value is used, the agent will attempt to create the directory.
Type
String
Default
info
The log verbosity level. When you change this setting in the agent yaml config file, it will update dynamically. However, the environment variable and system property will not update dynamically.
The agent uses its own log file to keep its logging separate from that of your application. Valid options, in order of verboseness, are:
off
severe
warning
info
fine
finer
finest
注意
Do not use debug or trace logging unless New Relic Support asks you to use them. These levels of logging can generate excessive overhead. For most situations, use info.
This setting is dynamic, so running agents will notice changes to newrelic.yml without a JVM restart.
Type
Integer
Default
0
The log file size in kilobytes at which log files are rotated. Set to 0 for no limit.