Comments (5)
Should we pass a &mut PathBuf to before_file_open handler to allow users to change the file path?
I don't think this is necessary since you can change the path via FileSinkBuilder::path
. A &Path
shoud suffice.
from spdlog-rs.
I don't think this is necessary since you can change the path via
FileSinkBuilder::path
. A&Path
shoud suffice.
But for RotatingFileSink
, a &mut PathBuf
allows the user to customize the rotated file name before creating the file, rather than renaming it after the file is closed. (context #49)
I'm thinking if there are any cons to doing it this way.
from spdlog-rs.
The reason I feel a bit strange is that if you give your user a &mut PathBuf
in the hook, it strongly expresses the intent that the hook exists solely for a very specific purpose: changing the filename. To implement this very specific requirement, a better API might be:
pub trait RotateFileOpener {
fn open(&self /*, other params */) -> PathBuf;
}
impl<ArgBP, ArgRP> RotateFileSinkBuilder<ArgBP, ArgRP> {
pub fn opener(self, opener: Box<dyn RotateFileOpener>) -> Self {
todo!()
}
}
The hook can be kept (and it should be kept). It's purpose is to give the user a change to do monitoring and bookkeeping jobs. But I still don't think changing the filename from the hook is a good idea. We have other approaches to express the indent more clearly.
from spdlog-rs.
The reason I feel a bit strange is that if you give your user a
&mut PathBuf
in the hook, it strongly expresses the intent that the hook exists solely for a very specific purpose: changing the filename.
Makes sense. So let's keep &Path
for before_file_open
of RotatingFileSink
.
The new trait RotateFileOpener
is a bit verbose if it's just for custom paths, and it should be designed to be a bit more powerful if it goes this way. Another option would be to just add something like the filename_calculator
in C++ spdlog. But for now let's table this idea, it seems a bit out of the scope of this issue. If anyone is interested in this in the future we will discuss it further in a new issue. For users who currently need to customize file names, they can workaround renaming files in after_file_close
.
So the current signatures of the event handlers will be
(reference from C++ spdlog)
before_file_open : impl Fn(path: &Path)
after_file_open : impl Fn(path: &Path, file: &mut File)
before_file_close : impl Fn(path: &Path, file: &mut File)
after_file_close : impl Fn(path: &Path)
Is it right?
from spdlog-rs.
So the current signatures of the event handlers will be
[...]
Is it right?
What's the purpose of the &mut File
parameter? This would allow the user to replace the File
object completely through the mutable reference.
from spdlog-rs.
Related Issues (15)
- Tracking issue for pattern formatters HOT 1
- [Feature Request] Create logger builders from existing loggers HOT 6
- [Bug Report] Source data is not displayed when using log crate HOT 5
- Tracking issue for config (deserialization) HOT 15
- pattern {tid} not shows the source threadid by async sink HOT 1
- Can't build with 0.3.9 - undefined reference to `gettid' HOT 5
- Failed to build for iOS HOT 7
- [Bug Report] Unnecessary recompiling spdlog-rs HOT 4
- how about upgrade syn package from 1 to 2 HOT 2
- Tracking issue for `runtime_pattern!` macro HOT 1
- [Feature Request] Support formatting parameters in pattern placeholders
- [Feature Request] Allow calling other macros in logging macros HOT 3
- [Bug Report] fails to build on Linux with latest nightly Rust HOT 2
- [Bug Report] `AsyncPoolSink` may lose the last log records and panic on program exit HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spdlog-rs.