Skip to content

Add logging macros with native log format syntax? #10

Description

@madsmtm

It is useful to be able to emit logs with more detailed information, see e.g. #2. In particular, I think it'd be nice if I could write something like:

let log = oslog::OsLog::new(c"com.example.foo", c"my_category");
oslog::warn!(&log, "User number %i's password %{private}s", 1234, c"password");

And have that be equivalent to the following in C:

os_log_t log = os_log_create("com.example.foo", "my_category");
os_log_warn(log, "User number %i's password %{private}s", 1234, "password");

If nothing else, implementing the C macros in Rust would allow us to avoid the need for a build script, which should make cross-compiling easier. On top of this, we can then implement the oslog::Logger for the log framework, or tracing-oslog could use it to implement the things they need.

Basically, I'm suggesting taking this implementation which allows using os/log.h directly in Rust, and combining it with checks in printf-wrap to make a safe macro with printf-like semantics. I'd also want to add support for activities and signposts.

The difficulty in the implementation this is that the format string must be placed in a special global static (__oslogstring). Swift also special-cases this. So integration with crates like log or tracing will still have to go through extra indirection and a call like "%{public}s".

Would you accept a PR that implements something like this?

I'd also be interested in co-maintaining the crate if you need it (especially if I'm gonna rewrite a large part of it).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions