Spdlog: Only write to file if there is an error - c++

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.

Related

Logging DJI error codes to ofstream

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.

Win32Com Error Running with Task Manager

I have a python script that calls open an Excel file, calls a macro in the file, then closes. If I run the file from the CLI, it works. If i put it in Task Scheduler, I get an error from win32com.
Method opening the Excel file:
import win32com.client as WinCom
if os.path.exists(reportGeneratorFileName):
try:
xl = WinCom.Dispatch("Excel.Application")
xl.Workbooks.Open(Filename=os.path.abspath(reportGeneratorFileName))
xl.Application.Visible = False
xl.Application.Run("'{}'!Runner.Runner".format(reportGeneratorFileName))
l.info('Start Sleeping')
# Async mode of pythonw causes this to finish before the file is made
time.sleep(300)
l.info('Done Sleeping')
xl.Application.Quit()
except Exception as e:
l.error('Error updating file')
l.error(e, exc_info=True)
This is the Error i get:
06/04/2018 06:56:19 AM ERROR: (-2146959355, 'Server execution failed', None, None)
Traceback (most recent call last):
File "LAW Report.py", line 846, in createReport
xl = WinCom.Dispatch("Excel.Application")
File "c:\python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "c:\python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2146959355, 'Server execution failed', None, None)
Now i am running 64 bit python 2.7 and 64 bit win32com while office is 32 bit, but as I said above, if I just run the script from the CLI it runs fine, just not from task manager. I am running this on a Windows Server 2012R2. I have tried configuring the task for 2008, 2008r2, and 2012r2. I also tried with highest privileges. I do need this to be able to run whether user is logged on or not. Everytime I have tested, the user has been logged on.
You need to
1) setup permissions in DCOMCnfg utility for user under which you're running -or-
2) change user to your desktop user account.
But first you need to get proper error code, not a generic message.
Pay attention that this should be considered as temporary solution since DCOM is badly supported by MS for automation as service. Consider switching to any library as soon as possible. There're numerous problems with Excel interop: you will have to reboot server from time to time, performance degradation with subsequent calls, you can't run Excels in parallel because of a good chance of errors, etc...
I encountered the same error of which my program can run from command prompt but not from task scheduler.
I solved this issue with these settings of task properties in task scheduler:
1. General->Security Options
a. make sure same user account you used to run python/microsoft program.
b. checked "Run only when user is logged on.
c. unchecked "Hidden"
For 1a, I'm using DOMAIN\userid that I used to login my laptop/PC.
This is the only way I found in order for the task scheduler to run successfully. Hope this helps.

informatica is taking the source file as the indirect file

I had made a source file data type change in source analyzer. I did realize that it had made the mapping invalid. I ran the mapping and it failed. Now I reverted the change, validated the mapping, check in the mapping, validated the workflow, check in the workflow.
Now I am getting the error:
Severity Timestamp Node Thread Message Code Message
INFO 7/23/2015 10:40:03 AM node01_CSADevelopment READER_1_4_1 FR_3055 Reading input filenames from the indirect file [<input_directory_folder>/<input_file>].
Severity Timestamp Node Thread Message Code Message
ERROR 7/23/2015 10:40:03 AM node01_CSADevelopment READER_1_4_1 FR_3000 Error opening file [<input_file_folder>/<header_of_the_input_file>]. Operating system error message [No such file or directory].
here the term "input file" is the file which I wanted to load and "header_of_the_input_file" is the header of the input file.
I don't understand, why it is happening. I had just made a small change and then reverted it.
The error is just saying the filenames mentioned in the indirect file are not found. So, you just need to make sure all the source files are there in the "input_file_folder"
There is a property in the session to configure the source file as indirect. An indirect file contains a list of source filenames. Informatica reads all the files listed and loads the data. If you think you have inadvertently made the source file indirect, you can change the option in session properties (mapping tab -> Source Qualifier)
It does not have anything to do with the datatype change and reverting it.

log4cpp and odd console output

I am trying to use log4cpp on my project. But everytime I try to write a log message in addition to the log message going to the log file I also get this message to the console window.
/var/log/ngis/mixer.log.3
Here is the copy of the appropriate section of my log4cpp.properties file.
# This is for the rolling file Appender, this will not send log info
# to the syslog.
log4cpp.rootCategory=INFO, rootAppender
log4cpp.appender.rootAppender=RollingFileAppender
log4cpp.appender.rootAppender.fileName=/var/log/ngis/mixer.log
log4cpp.appender.rootAppender.maxFileSize=10MB
log4cpp.appender.rootAppender.maxBackupIndex=3
log4cpp.appender.rootAppender.BufferedIO=true
log4cpp.appender.rootAppender.BufferSize=100000
log4cpp.appender.rootAppender.layout=PatternLayout
log4cpp.appender.rootAppender.layout.ConversionPattern=%d[%p %c] %m%n
The data is going to the log file. I have tried creating a file called /var/log/ngis/mixer.log.3 but that does not help.
if I change the .maxBackupIndex=3 to .maxBackupIndex=2 then the message changes to:
/var/log/ngis/mixer.log.2

how to print logs into only one file by google glog

I'm now using google glog. When I'm debugging the program, every time the process restart, a new log file generated, identified by the new pid as filename's sufix, like this
ied_config.20131220-142934.4524
ied_config.20131220-171227.3948
ied_config.20131225-170117.7032
ied_config.20131225-170131.5200
ied_config.20131225-171450.7820
ied_config.20131225-172336.4116
ied_config.20131225-172924.6120
ied_config.20131225-173000.2980
ied_config.20131225-173037.1960
ied_config.20131225-173144.7304
ied_config.20131226-095843.1012
smv_client.20131219-082120.7184
smv_client.20131219-162339.5508
smv_client.20131219-163055.6156
smv_client.20131219-163155.4892
smv_client.20131219-163206.5576
smv_client.20131219-163216.6340
smv_client.20131219-163236.6952
smv_client.20131219-163307.7940
smv_client.20131219-163317.4920
smv_client.20131219-163347.6556
smv_client.20131219-163408.5124
smv_client.20131219-163428.2644
smv_client.20131219-163448.6040
smv_client.20131219-163529.6948
smv_client.20131219-163539.1592
smv_client.20131219-163549.3776
smv_client.20131219-172949.5412
smv_client.20131219-173000.4180
smv_client.20131219-173010.7432
smv_client.20131220-170628.636
smv_client.20131220-170930.3904
smv_client.20131226-095841.1296
I want to join these log just into one file for each program, I can't file the configuration for the glog ,any helps?
If you want to change the name of log files, you may need to call SetLogDestination():
google::SetLogDestination(google::INFO, "/var/tmp/another_destination.INFO");
From release 0.5 on May 8, 2021
Allow a log file to be simply named "foobar.log" with no appended
string #124
google::SetLogDestination(google::INFO, "/var/tmp/another_destination.INFO");
FLAGS_timestamp_in_logfile_name = false;