Feature #7240
closedUse WLogger as a façade for custom logger implementations?
0%
Description
Currently WServer
's WLogger
output can be sent to a file or to an ostream
, and wthttp
's access logger will log to either stderr
or a file.
However, users may be using their own logging library, like Boost.Log, or POCO::Logger, directly using syslog(3)
, systemd's sd_journal_print
, etc.
It should be possible to let them implement some interface or callback, so they can process logs however they see fit.
Updated by Roel Standaert over 5 years ago
Related: Wt::Dbo currently logs to std::cerr
. It should be possible to send these logs to the WServer
's logger when used in the context of a Wt application, or some other logger.
Updated by Marco Craveiro over 5 years ago
In addition, Wt also logs to std::cerr when successfully opening a file (src/Wt/WLogger.C):
if (ofs->is_open()) {
std::cerr
<< "INFO: Opened log file (" << path.c_str() << ")."
<< std::endl;
o_ = ofs;
ownStream_ = true;
} else {
delete ofs;
std::cerr
<< "ERROR: Could not open log file (" << path.c_str() << ")."
<< "We will be logging to std::cerr again."
<< std::endl;
o_ = &std::cerr;
ownStream_ = false;
}
}
Ideally, it would be nice not to write anything at all on success - not even to std::out. Perhaps this makes more sense if you take into account my particular use case. I am trying to use the log management system in AWS, which captures all writes to the console; thus, I'd rather not have any text coming up which is not directly produced by the application logging so that in the future I can push those messages as events into some kind of searchable log. As things stand, I get:
2019-09-20 11:49:09.065640 [INFO] [backend.web] Started web v0.0.1
2019-09-20 11:49:09.065769 [INFO] [backend.web] Starting wthttp server.
INFO: Opened log file (/dev/null).
INFO: Opened log file (/dev/null).
2019-09-20 11:49:11.654205 [INFO] [backend.web.application] [OV3zJ3ocP2RGPCmg] ::Creating application
2019-09-20 11:49:11.654444 [INFO] [backend.web.application] [OV3zJ3ocP2RGPCmg] ::Finished creating application
2019-09-20 11:49:12.605736 [INFO] [backend.web.application] [UISwxg5es7PPtVBM] ::Creating application
2019-09-20 11:49:12.606238 [INFO] [backend.web.application] [UISwxg5es7PPtVBM] ::Finished creating application
2019-09-20 11:49:16.128893 [INFO] [backend.web] Finished wthttp server.
I'd love to be able to get rid of those "Opened log file" lines.
Many thanks for your time.
Updated by Marco Craveiro over 5 years ago
Actually, this change seemed so trivial, I decided to fire off a PR [1]. Let me know what you think.
Cheers
Marco
Updated by Roel Standaert about 5 years ago
As you can see in my reply on GitHub, we're not willing to just merge that PR like that, since we (and probably many others) actually find it useful.
I see that you are logging to /dev/null
, though? Instead of logging to /dev/null
, you can actually set the log level to -*
with <log-level>-*</log-level>
, and disable the access log with --access-log=-
instead of using /dev/null
.
Updated by Marco Craveiro about 5 years ago
Hi Roel,
Well, you guys are the wt maintainers and you have a much better perspective than me across all users so I understand and respect your position. I'll close the PR. Thanks for the detailed feedback, it is appreciated.
With regards to your suggestions, I'm not entirely sure how that would help given that you are writing to std::err? Its only the std::err entries that are causing me problems, the remaining ones are fine.
My solution, when I have more time, will be a bit of a bad hack: I'm going to do a copy and paste "fork" wthttpd and update it with my own logging. Not pretty but should at least address the issue at hand. I'll revisit it properly once you move towards a WLogger interface...
Updated by Roel Standaert about 5 years ago
With regards to your suggestions, I'm not entirely sure how that would help given that you are writing to std::err? Its only the std::err entries that are causing me problems, the remaining ones are fine.
If you do not set a file to output to, i.e. <log-file></log-file>
, then it shouldn't log anything at all? In that case setFile()
is never actually called.
What could be an option is logging the successful file open to the previously configured ostream
(if that is not a file, default is std::cerr
)? It could maybe then be possible to actually disable this log message by setting the log level to -info:WLogger
.
Of course, this does not help with Wt::Dbo
's logging, which is indeed currently hard coded to std::cerr
(because we don't want Dbo to depend on Wt).
Updated by Marco Craveiro about 5 years ago
If you do not set a file to output to, i.e. , then it shouldn't log anything at all? In that case setFile() is never actually called.
Aha, sorry I was a bit slow - I get you now. Yep that sounds like a plan, at least as a first stab.
What could be an option is logging the successful file open to the previously configured ostream (if that is not a file, default is std::cerr)? It could maybe then be possible to actually disable this log message by setting the log level to -info:WLogger.
Yep that sounds good too as a longer term solution. Nice one.
Of course, this does not help with Wt::Dbo's logging, which is indeed currently hard coded to std::cerr (because we don't want Dbo to depend on Wt).
Understood. To be honest, the logging situation in C is just annoying. I think we need some kind of "meta-logging" library like they have in Java that could then map to the library used by the user. However, it is what it is.
Updated by Stefan Ruppert about 5 years ago
Marco Craveiro wrote:
Understood. To be honest, the logging situation in C is just annoying. I think we need some kind of "meta-logging" library like they have in Java that could then map to the library used by the user. However, it is what it is.
We at MyARM are also interested in way to redirect Wt log messages into our own logging system.
Regards,
Stefan
Updated by Roel Standaert almost 5 years ago
- Status changed from New to Resolved
I added WServer::setCustomLogger()
, Wt::Dbo::setCustomLogger()
, Wt::Dbo::logToWt()
(to redirect Dbo's logger to Wt's logger), and the abstract class Wt::WLogSink
.
Updated by Roel Standaert over 4 years ago
- Status changed from Resolved to Closed