Add the ability to specify an appender for output to STDERR
in the config file.
At the moment there is only ConsoleAppender
which outputs to STDOUT.
Perhaps a separate ErrorConsoleAppender
could be added. Or perhaps a stream
option could be added to ConsoleAppender
. Or separate OstreamAppender
with a stream
option.
From what I've read, log4j ConsoleAppender accepts a parameter target=System.err.
http://twiki.mssl.ucl.ac.uk/twiki/bin/viewfile/Software/Odyssey?rev=1;filename=logging.properties
The feature looks to be reasonable since it is useful and it follows log4j design.
Current ConsoleAppender (which is of class log4cpp::OstreamAppender actually) redirects all its input into std::cout.
It could be an option of ConsoleAppender which will redirect input into std::cerr.
The topic to discuss is what values of that option should look like.
C++ and C runtime library have no notion of System.err neither System.out.
So the value of log4j.appender.appendername.target should probably be either STDERR or STDOUT.
How does this patch look? Haven't tested but wanted to see if this matches what you all were thinking three years ago. I would also like this feature implemented.
Will have a look at the code.
I believe we should invent and develop some kind of the test for this feature
I am trying to but I can't build the library--the instructions at http://log4cpp.sourceforge.net/#building seem to be missing steps. Even after messing around with autoconf and automake the configure script that finally generated failed with errors. Can you please advise on how you build the library?
Andrew,
It works well on Ubuntu 14 with provided .tar.gz archive
if you check out code from repository, then you need to run ./autogen.sh first. ( http://log4cpp.sourceforge.net/#cvs )
May be it is worth to try again with clean directory and fresh checkout?
Regarding your patch, it looks ok.
Comparison for stdout probably should stay as the first, as it is more expected. And comparisons are better to be done on both uppercased or lowercased operands.
Thanks, tried again and it works; I updated libtool and I think that did the trick. I now am trying to write a quick test to prove that "...target=STDERR" actually prints to STDERR but I'm having issues with getting the test to run. I added my CPP file to the Makefile.am in tests but "make clean; make check" isn't running it; what else do I have to do?
Also, I have committed the patch with the changes you suggested to my own branch. Do you want me to send a PR for that so we can review and merge separately from the test?
Last edit: Andrew Brown 2016-04-04
After you modified Makefile.am and rerun ./configure; make, it must run new test as well.
You may have a look at sample of similar change: https://sourceforge.net/p/log4cpp/codegit/ci/1d93139cc8d083d38d3ab832283b0a86c900a9e4/#diff-18
Thanks, that worked; I changed the Makefile.am and jamfile and the tests now run. Unfortunately, the test fails because of some nifty output redirection by the wrapper script that runs the tests. As you can see from the attached patch, I was trying to read from /dev/stderr in a separate thread but I am not convinced this will ever work, especially on other non-Linux platforms.
Also, I submitted the original code patch as a PR.
Alex, any comments?
Andrew,
Sorry, I expected that you would receive notification I left at
https://sourceforge.net/p/log4cpp/codegit/merge-requests/3/
Merged into master; added lines to test configs.
Alex, quick question: what version will this be published in?
The next RC.
Hopefully, in next few days