reverie-rs / reverie

trace and intercept linux syscalls.
Other
14 stars 5 forks source link

Support other backends for logging in the tool #59

Open ckoparkar opened 4 years ago

ckoparkar commented 4 years ago

At the moment reverie does have a logger. To use it in a tool, one needs to initialize it with tools_helper::logger::init() and pass an environment variable TOOL_LOG=level to the reverie binary. Then, all the log crate macros like info!, debug! etc log their output to stdout.

It would be really nice if the tool could also log things somewhere other than stdout, to a file for example.

wangbj commented 4 years ago

Thanks for submitting this issue. logging to file should be relatively easy, with one caveat: we probably want allocate a predefined FD number, preferably close to 1024. Because open an fd in the very same memory address space has visible effects to the tracee, for instance, if you just open a log file with fd=3, then the musl build script would fail, because it has bellow script in its configure:

    exec 3>&1 1>config.mak

In short, it expects configure script to be opened as fd=3, which is true if you run the script directly from shell environment.

ckoparkar commented 4 years ago

Okay. Maybe instead of accepting any Write handle, the logger could offer a few different options ? For example:

enum LogBackend {
  Stdout,
  Stderr,
  File { path: String },
  ...
}

fn init(backend: LogBackend) {
....
}

I'm not saying this should the API or anything but with something like this, all the details of how to initialize the bakend are hidden away from the tool and reverie is free to do the right thing for each of these.