-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for file based logging in ios and macos #1713
base: develop
Are you sure you want to change the base?
Conversation
Tried that a couple of times, but this never returns logs that we are interested in. We are missing a uniffi call to pass in the log path? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @jmwample and @rokas-ambrazevicius)
nym-vpn-core/crates/nym-vpn-lib/src/platform/swift.rs
line 8 at r1 (raw file):
use log::LevelFilter; use oslog::OsLogger; use pretty_env_logger::env_logger::fmt::Target;
Given that we already use tracing
a lot, I think it would make sense to stick to it especially because it implements extensible plugin system capable of writing to file, oslog, eventlog, and many other target destinations.
nym-vpnd/src/logging.rs
has example of how to set up logging to file and I think we could also leverage tracing-oslog instead of oslog::OsLogger
for better integration with tracing.
nym-vpn-core/crates/nym-vpn-lib/src/platform/swift.rs
line 12 at r1 (raw file):
/// Path used for MacOS logs #[cfg(target_os = "macos")] const MACOS_LOG_FILEPATH: &str = "/var/log/nym-vpnd/daemon.log";
It would be better to accept PathBuf
as argument toinit_logs()
since this is not a daemon, but a static library that's linked into each process on iOS. Each process will provide individual path to log file to which the sandboxed executable has access to.
nym-vpn-core/crates/nym-vpn-lib/src/platform/mod.rs
line 139 at r1 (raw file):
} pub fn init_logger() {
Missing PathBuf
to log file on iOS/macOS.
My current concerns are that this may be between a rock and a hard place. If we use Also I don't know if / when it is used, but the uniffi exported function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 8 files at r2, 1 of 2 files at r3.
Reviewable status: 6 of 8 files reviewed, 1 unresolved discussion (waiting on @jmwample and @rokas-ambrazevicius)
a discussion (no related file):
I am finally back at reviewing this.
The scope of this work was much smaller in the beginning. I think we should focus on solving two specific problems without trying to grasp 5 platforms or unify logging initialization because this seems to be difficult.
- Make it possible to log to file on iOS
- Log to file on macOS
The steps that I would take to achieve both:
- Make it possible to pass a path to file on iOS (nym-vpn-lib) via call to uniffi, i.e modify
fn initLogger()
to acceptOption<PathBuf>
and if set, use the given path for writing log in it (configure tracing). If you need to store aWorkerGuard
, put it in thelazy_static!
section inplatform/mod.rs
. - On macOS, when
_as_service == true
, instead of calling intonym_vpn_lib::swift::init_logs(..)
add logging to oslog with the new tracing plugin.
We can look into rolling strategy in a separate PR as we need logs like yesterday. Also we don't really care about double initialization as this should never happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r3.
Reviewable status: 7 of 8 files reviewed, 1 unresolved discussion (waiting on @jmwample and @rokas-ambrazevicius)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 8 files at r2.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @jmwample and @rokas-ambrazevicius)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed (commit messages unreviewed), 1 unresolved discussion (waiting on @pronebird and @rokas-ambrazevicius)
a discussion (no related file):
Previously, pronebird (Andrej Mihajlov) wrote…
I am finally back at reviewing this.
The scope of this work was much smaller in the beginning. I think we should focus on solving two specific problems without trying to grasp 5 platforms or unify logging initialization because this seems to be difficult.
- Make it possible to log to file on iOS
- Log to file on macOS
The steps that I would take to achieve both:
- Make it possible to pass a path to file on iOS (nym-vpn-lib) via call to uniffi, i.e modify
fn initLogger()
to acceptOption<PathBuf>
and if set, use the given path for writing log in it (configure tracing). If you need to store aWorkerGuard
, put it in thelazy_static!
section inplatform/mod.rs
.- On macOS, when
_as_service == true
, instead of calling intonym_vpn_lib::swift::init_logs(..)
add logging to oslog with the new tracing plugin.We can look into rolling strategy in a separate PR as we need logs like yesterday. Also we don't really care about double initialization as this should never happen.
Some good points here. Great to see work to sort out a unified logging approach, though for now a quick solution as an interim step would be good
5a4a0db
to
b49f722
Compare
As logs are not available to iOS or MacOS apps through the console, this PR makes it possible for logs to be written to file.
On iOS if a path is provided in the
"IOS_LOG_FILEPATH"
environment variable this function will attempt to open that file and use it as the logging sink. On MacOS logs are written to the static"/var/log/nym-vpnd/daemon.log"
.If we are unable to open the log file for either iOS or MacOS we default to writing to the default (console) output.
Edit: the
oslog
crate that we are using for logging in iOS/MacOS does not support switching the sink/output of the logging as OSLog is a specific apple logging subsystem. We can possibly just use something likeenv_logger
orpretty_env_logger
to write to file, but it seems that this may not be necessary as iOS apps may be able to read from their own logs to the OSLog subsystem (i.e. based onnet.nymtech.vpn.agent
).This change is