Set-default-target
Update the default target used by the shared default logger returned by default_logger() and by the global write helpers such as info(...) and error(...).
Interface
pub fn set_default_target(target : String) -> Unit {}input
target : String- New default target string for the shared global logger configuration.
output
Unit- No return value. The stored default target is updated for later global calls.
Explanation
Detailed rules explaining key parameters and behaviors
- The function updates the internal
Ref[String]used bydefault_logger(). - It does not mutate any custom
Loggervalues created earlier. - Later global writes inherit the new target unless a different explicit logger path is used.
- Any explicit logger value that was already created earlier keeps the target it captured at creation time.
- This is useful when one application wants the convenience of global helpers while still labeling records consistently.
How to Use
Here are some specific examples provided.
When Label Global Application Logs
When global helper calls should carry one stable target:
set_default_target("app")
info("service started")In this example, the emitted global record uses app as its target.
When Re-scope A Temporary Execution Context
When a script or tool should tag its own global output:
set_default_target("tool.migration")
warn("running fallback path")In this example, later global writes stay grouped under the migration target.
Earlier explicit logger values still keep whatever default target they captured before this change.
Error Case
e.g.:
If
targetis empty, global writes remain valid and simply omit the target unless another logger path supplies one.Previously created custom loggers are unaffected because they do not read the shared default target reference afterward.
Notes
This API is best suited for small apps, scripts, or a single shared logging entry path.
Call
default_logger()again after changing the default if a fresh explicit logger value should reflect the new target.Prefer explicit child or per-component loggers when target structure needs to vary across subsystems.