Use assembly overrides for logging
In some cases, you may want to use assembly overrides to capture the logs of a component during startup.
For example, if you want to capture the logs for the component
my-component-logging:
In your Fuchsia checkout, make a
//local/BUILD.gnfile:assembly_developer_overrides("netstack-overrides") { platform = { diagnostics = { component_log_initial_interests = [ { component = "core/network/netstack" log_severity = "debug" }, ] } } }This is what this
BUILD.gnfile indicates:- The assembly developer override is named
netstack-overrides. You can use any meaningful identifier for this field. - The keys
platform,diagnostics, andcomponent_log_initial_interestsare all based on values from valid product configuration values. For more information, seeplatform. - In this example, you used the component moniker,
core/network/netstack, but you can also use the component URL,fuchsia-pkg://fuchsia.com/netstack3#meta/netstack3.cm. For more information on monikers, see component moniker. - For the
log_severityvalue, specify the minimum log severity to log. For example,debugseverity. Alternatively, you could also usetracewhich is a lower severity thandebug. However, you can use any level of log severity. For more information about log severity, see Choosing severity for log records.
- The assembly developer override is named
Once you have made a
//local/BUILD.gnfile that meets your requirements, you can set yourfx setcommand to use this assembly platform configuration. For example:fx set --assembly-override=//local:my-component-loggingBuild Fuchsia:
fx buildYou should now be able to run or OTA Fuchsia as you normally would.
Restrict log severity
By default, a test will fail if it logs a message with a severity of
ERROR or higher. This often indicates that an unexpected condition had
occurred during the test, so even if the test passes it's often useful to bring
this to the developer's attention.
This default behavior can be changed, for each test package, to allow logs at
higher severities, or to fail a test that logs at lower severities. For example,
a test might expect to log an ERROR, in order to cover a failure condition and
recovery steps.
A test might expect to log at ERROR severity. For example, the test might be
covering a failure condition & recovery steps. Other tests might expect not to
log anything more severe than INFO.
For instance, to allow a test to produce ERROR logs:
fuchsia_component("my-package") {
testonly = true
manifest = "meta/my-test.cml"
deps = [ ":my_test" ]
}
fuchsia_test_package("my-package") {
test_specs = {
log_settings = {
max_severity = "ERROR"
}
}
test_components = [ ":my-test" ]
}
To make the test fail on any message more severe than INFO,
set max_severity to "INFO".
Valid values for max_severity: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.
See also: choosing severity for log records.