WASI Logging

A proposed WebAssembly System Interface API.

Current Phase

WASI-logging is currently in Phase 1.

Champions

  • Dan Gohman

Phase 4 Advancement Criteria

The Phase 4 Adancement Criteria for this API are not yet defined.

Table of Contents

Introduction

WASI Logging is a WASI API for emitting log messages.

Goals

The primary goal of WASI logging is to be a simple logging API usable as a stderr destination in commands and as a logging output in headless programs.

Non-goals

WASI Logging is not aiming to be a general-purpose output stream, with support for error reporting or asynchronous operation.

API walk-through

There are two main use cases.

Logging use case

The logging API can be used to log simple messages:

   log(Level::Info, "fyi", "The program is running");

Stderr use case

The logging API can be used as an output for a command-style stderr.

   log(Level::Info, "stderr", "Message printed to stderr in a command");

Detailed design discussion

What levels should there be?

The log levels are similar to those of log4j, the Rust log crate, the Python log levels, the Ruby log levels, and the .NET log levels.

It excludes log4j's and Ruby's FATAL level, Python's CRITICAL, and .NET's Critical level. The recommended behavior on a FATAL, CRITICAL, or Critical error is to emit an Error-level error and to trap.

Another similar API is the POSIX syslog function. LOG_EMERG, LOG_ALERT, and LOG_CRIT have no corresponding level, because WASI programs don't have visibility into how their own errors affect "the system" as a whole. A plain Error level should be used, optionally with a trap if it's desirable to halt execution. And LOG_NOTICE and LOG_INFO both correspond to Info, because other popular systems don't make a distinction between these levels.

What should the context be?

Currently the context parameter is an uninterpreted string, because it's the simplest thing that works for now. It may evolve into something else though.

Stakeholder Interest & Feedback

TODO before entering Phase 3.

References & acknowledgements

Many thanks for valuable feedback and advice from:

  • Luke Wagner