daboross/fern

custom target string

keepsimple1 opened this issue · 2 comments

The default target for log messages is <crate_name>::<module_name>::<line_num> or <crate_name>::<line_num> for logs in the crate root. And targets can also be set with info!(target: "target-name", ...), but it has to be done for every log message.

Is there a way to set a custom target string pattern for all logs? For example, set it as <module_name>::<line_num> ?

Thanks.

Hi,

If you want to do this, you'll need to do the logic in a custom formatter. Fern gets the module name from log.rs as a string, "<crate_name>::<module_name>", so if you want to remove the crate name, you'll need to parse it and cut that part off.

I think something like module_name.splitn(2,"::").nth(1).unwrap() should work for that.

As for adding the line number, that should also be fully possible. The line number is part of the metadata, so just add a :: to the format string, and put the line number after it.

Let me know if that works, or if a full example would be more helpful.

Thanks, that helps!