Google is committed to advancing racial equity for Black communities. See how.

Logging in Rust

Rust programs on Fuchsia generally use the log crate and its info!/warn!/error! macros. The fuchsia_syslog crate is used for initialization.

See the language agnostic logging docs for more information about recording and viewing logs.


GN dependencies

The necessary crates can be included with two additions to deps in

deps = [
  "//src/lib/syslog/rust:syslog",   # for initialization
  "//third_party/rust_crates:log",  # for recording messages

See Rust: Overview for more information about building Rust within Fuchsia.

Component manifest dependency

Ensure that your component has the required capabilities to log by including the following in your component manifest:


  "include": [


  include: [

The syslog library will fallback to stderr if the LogSink connection fails.


The Rust log crate must be connected to the Fuchsia backend before it can emit messages. Failure to initialize the library will result in dropped messages.


In your component's

use fuchsia_syslog as syslog;

fn main() {
    // configures a single tag with the process name

With tags

By default the process name is used as the tag for all log messages. Tags can be used to further categorize log messages from the program, and they can also be globally overridden.

use fuchsia_syslog as syslog;

fn main() {
    // overrides the use of process name for tag

    // additional tag for just this message
    syslog::fx_log_info!(tag: "init", "an update on program initialization");

Configure severity

The syslog crate starts at INFO severity but can be overridden.

use fuchsia_syslog as syslog;

fn main() {

    // suppress INFO and below

Recording messages

Most uses of logging are with the log crate's macros:

trace!("something happened: {}", 5); // maps to TRACE
debug!("something happened: {}", 4); // maps to DEBUG
info!("something happened: {}", 3);  // maps to INFO
warn!("something happened: {}", 2);  // maps to WARN
error!("something happened: {}", 1); // maps to ERROR

The fuchsia_syslog crate also offers macros like fx_log_info!, which allow manually specifying the tag of a message.

Standard streams

println!, eprintln! etc. go to standard out (stdout) and standard error (stderr).

See stdout & stderr in the language-agnostic logging docs for details on the routing of stdio streams in the system.