Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Centos Linux
I have a class that instantiates other classes and want all to write to a single log file. I am unable to find the correct syntax and am not certain that this can easily be done. My searches for topics such as sharing a log file lead to results on piping outputs rather than from within an application.
Below is the basic concept. Can this be done? Maybe some search hints to find what others have discussed?
file a.h contains
Code:
class a{ ...
public
a( );
private:
std::ofstream m_logs;
...}; // end of class a
file a.cpp contains
Code:
a::a() {
m_logs.open( "/tmp/a_logs.txt" );
m_logs << "write a stuff"
b = new class_b( std::ofstream & log_file );
...} // end of a constructor
file b.h contains
Code:
class b{ ...
public:
b( std::ofstream & log_file ); // compile error here
private:
void x( );
std::ofstream m_logs;
... } // end class b
The text from the compile error is:
Quote:
error: could not convert '0l' from 'long int' to 'std :: ofstream& {aka std :: basic_ofstream<char>&}'
(side note: added spaces around the some of the colons to prevent emoticons)
I do not understand why it declares that std :: ofstream is a long integer;
file b.cpp contins
Code:
b :: b( std::ofstream & log_file ) {
m_logs = log_file; // ?
m_logs << "write b::b stuff" << std::endl;
x();
...} // end constructor b
b :: x(){ ...
m_logs << "write b :: x stuff" << std::endl;
... } // end function b :: x()
I don't see where in a.cpp you pass the constructor an ofstream instance? Maybe replace:
Code:
b = new class_b( std::ofstream & log_file );
with:
Code:
b = new class_b( std::ofstream & m_logs );
My first thought was: Is there some reason you can't just log to the system logger and configure it to write everything from your application to a specific file? I am sysad at my day job and would much rather an application log to the syslog than it's own file.
... I am sysad at my day job and would much rather an application log to the syslog than it's own file.
When developing an app and trying to find the defects I have put in, I don't want to write copious quantities of debug info to any system wide log. Thanks for the tip and I am still working on it.
I am pretty rusty on my C++, it has been 3 years or so since I have written any C++. My recollection of new, constructors, etc is a bit foggy. I did a little bit of brushing up and found my comment on how the constructor is called is incorrect.
I think pan64 is probably correct. Try this:
Code:
cd /path/to/src/tree
find . -type f -exec grep -l log_file {} \;
This will show you all files with log_file in it within your source tree.
While I understand that you have modified your question, it is clearly a continuation of this question where you've learned additional information, and are trying some next steps.
Both of these topics are more suitable for the Programming forum, so I'm closing this one and moving your new question to Programming.
I may have a suggestion for that thread, however it won't be Qt specific because I no longer have a development system with Qt fully installed.
In the future, please consider marking this thread as solved, posting a link to your updated question here as a reference, and also consider which forums may be better for each question subject.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.