This may be a simple C++ question, but I'm having difficulty logging error code messages to an ofstream (logging to a file during flight to diagnose issues).
This is a code block of what I'd like to log
if (ACK::getError(startAck))
{
ACK::getErrorCodeMessage(startAck, __func__);
}
The line in the conditional returns null, and from what I am seeing, func is what logs the error to the standard output.
Anyone have any insight on how I could bring that message into an ofstream?
As of August 2018, the only way to log error messages to a file is to redirect your stdout stream to a file when running the program at a terminal.
Related
At the moment I am combining a file sink with a console sink. (see bellow)
std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(std::make_shared<spdlog::sinks::wincolor_stdout_sink_st>());
sinks.push_back(std::make_shared<spdlog::sinks::daily_file_sink_st>(path, 23, 59));
std::shared_ptr<class spdlog::logger> logger = std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks));
I still want to log everything to the console, but only write to the file if there is an error. this is because at the moment there are a lot of useless logs and files.
You can call file_sink->set_level(spdlog::level::error) to make it log only on error and more severe levels.
I have an App with a Poco module for internet connection to support users with legacy XP and Vista OS connecting with TLS1.2. There is a connection problem that returns a Poco error code but I don't know what that means. Here is part of the logging output:
poco_connection::end_receiving_response_body entered
poco_connection::close entered
poco_session::destroy_connection entered
poco_connection::end_transaction entered (code 0x00280166, hresult 0x00000000, closing: FALSE)
--------- 043d7450 (Closing request)
poco_connection::transaction_notify entered (code 0x00280166, hresult 0x00000000): Status: 3
Poco Communication Failed: code 0x00280166, hresult 0x00000000
poco_connection::~poco_connection entered
A little research shows there is a class Poco::Error that includes a method
static std::string getMessage(
int errorCode
);
which returns a text string for errors. Unfortunately I don't have source for the Poco module and so I can't add that translation call.
Since Poco is an open source project, can anyone point me to a code location where I can look up the mapping of Poco errors? Specifically error code 0x00280166
Seems I got lucky with a bit of googling
https://github.com/pocoproject/poco/blob/develop/Foundation/src/Error.cpp
But I don't think you're in luck, the code just assumes the error code is a windows system error code. And when I google 0x00280166 this page is the only hit.
# Open user's template file
if [catch { set f_id [open "$ex_doc_template_file" r] } res] {
# Close output file before abort
global html_output_file_id
catch { close $html_output_file_id }
MOM_abort "$ex_doc_template_file can not be open!"
}
I have the above code which need to open a template file, few days ago still working, yesterday just start showing can not be open, could help what is the problem on it?
The error message will be in the res variable. That should tell you what is wrong; add it to the abort message, perhaps like this:
MOM_abort "$ex_doc_template_file can not be open! $res"
Then you'll find that it is probably something obvious.
In general, when handling failures by reporting something, it's very useful to report the actual failure message as that often says what the problem is. I find that Tcl's messages are useful, at least for the immediate error. (The higher-level reasons why can take thought, of course.)
I am struggling to read from one input text file into a new text file using the Fortran compiler in Visual Studio 10. My input file is in gslib format (attached)
program main
! Unit numbers:
lisa = 4
lfke = 9
! Writing input data to file Lisa
open(unit=lisa,file='fake.dat',status='OLD',err=80)
open(unit=lfke,file='dlfke',status='NEW', err=80)
read(lisa,*,err=80)
read(lisa,*,err=80) line
write(9,*) line
close(unit=lisa)
close(unit=lfke)
80 stop 'ERROR in test file!'
end
This program is always going to produce the error message "ERROR in test file", whether or not there is an error. After executing line the close statements, it will next execute line 80 with the stop statement. You will probably find it easier, as your develop your program, to remove the err=80 tests in each IO statement. Then if there is an IO error, the program will automatically terminate and produce a specific message about the program. These err=branches are useful if you want to have your program handle the error, but with this implementation its hiding what the IO error was since all IO errors produce the same message.
I am having a strange problem in my code. I have many asserts scattered around the code and all have been working fine. Whenever an assert failed I got a message giving me line number of where the failure happened.
Today I wrote another assert in a function which loads a file. Just wanted to make sure that the fie existed. A very simple assert. Here is the relevant code:
//Check that the file exists and can be opened
FILE* f = fopen(filename, "rb");
#ifdef ASSERTIONS_ON
assert(f!=NULL);//#problem For some reason while all other asserts work, this one just crashes the program without reporting line
#else
if(f == NULL)
return MODEL_LOAD_FILENOTFOUND;
#endif
fclose(f);
I know that this does not help a lot but just wanted to showcase what my problem is. My OS is Windows 7. The compiler is GCC. The error message I get from Windows is the usual runtime error but without line reporting:
"The application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information"
What could be the problem? What can possibly cause an assert failure to just request termination without reporting a line where it happens, while in every other case in the same code it works as intended? Thanks in advance for any assistance!
You most likely have FUBAR'ed the stack somewhere before the assert executes.