Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_ELPP_NO_DEFAULT_LOG_FILE weird behaviour #109

Closed
bballer opened this issue Sep 12, 2013 · 15 comments
Closed

_ELPP_NO_DEFAULT_LOG_FILE weird behaviour #109

bballer opened this issue Sep 12, 2013 · 15 comments

Comments

@bballer
Copy link

bballer commented Sep 12, 2013

Given below code doesn't show any mistake and creates .\logs\myeasylog.log file. Using VC2012.

define _ELPP_NO_DEFAULT_LOG_FILE

include "easylogging++.h"

_INITIALIZE_EASYLOGGINGPP

int main(void)
{
LOG(INFO) << "Logging after configured!";
return 0;
}

@abumq
Copy link
Owner

abumq commented Sep 12, 2013

You are saying "NO DEFAULT LOG FILE" and then not specifying log file - where do you expect it to log to?

see this sample to specify log file or configure using

el::Configurations c;
c.setGlobally(ConfigurationType::Filename, "YourLogFile.log");
el::Loggers::setDefaultConfigurations(c);

Closing this!

@abumq abumq closed this as completed Sep 12, 2013
@bballer
Copy link
Author

bballer commented Sep 12, 2013

mkhan3189, thank you for very fast reply! Unfortunately given below code still creates .\logs\myeasylog.log and doesn't create .\YourLogFile.log

#define _ELPP_NO_DEFAULT_LOG_FILE
#include "easylogging++.h"
_INITIALIZE_EASYLOGGINGPP

int main(void) {
el::Configurations c;
c.setGlobally(el::ConfigurationType::Filename, "YourLogFile.log");
el::Loggers::setDefaultConfigurations(c);

LOG(INFO) << "Logging after configured!";
return 0;

}

@easylogging
Copy link
Contributor

Hey bballer,

Try this (second argument of setDefaultConfigurations i.e, "reconfigureExistingLoggers" defaults to false)

#define _ELPP_NO_DEFAULT_LOG_FILE

#include "easylogging++.h"
_INITIALIZE_EASYLOGGINGPP

int main(void) {
        el::Configurations c;
        c.setGlobally(el::ConfigurationType::Filename, "YourLogFile.log");
        el::Loggers::setDefaultConfigurations(c, true);

        LOG(INFO) << "Logging after configured!";
        return 0;
}

I removed existing logs\myeasylog.log file (to be sure on whats going on) and then ran above code and worked like charm! created file YourLogFile.log and logged to that. Let me know how'd you go

@bballer
Copy link
Author

bballer commented Sep 12, 2013

I deleted \logs\myeasylog.log, added second argument and ran the code. It has created \logs\myeasylog.log with 0 size and YourLogFile.log which finally has written the message "12/08/2013 03:10:32,381 INFO [default] Logging after configured!". Is there any way to avoid the creation of default log file?
Thanks again for your prompt replies.

@abumq
Copy link
Owner

abumq commented Sep 12, 2013

it's weird, i have tried several times and i dont get this file created (since I have _ELPP_NO_DEFAULT_LOG_FILE defined) this is only way - please ensure you are using latest version of lib

@bballer
Copy link
Author

bballer commented Sep 12, 2013

I deleted the easylogging++.h from project's directory, tried to build the project and it showed that easylogging++.h file is missing. Then I downloaded the latest version of the library and built the project without any errors. When I ran the executable it created .\logs\myeasylog.log again and .\YourLogFile.log. Is there any idea how to trace that "wrong" branch of the code?

@bballer
Copy link
Author

bballer commented Sep 12, 2013

I need to say that when I put breakpoint at the very first line in main() function the .\log\ directory is already created. So I guess that is is something in initialization of the Storage object, i.e. m_registeredLoggers->get(std::string(base::consts::kDefaultLoggerId));

@abumq
Copy link
Owner

abumq commented Sep 12, 2013

ok try searching for _ELPP_NO_DEFAULT_LOG_FILE in your header file - you are right many things are done at initialization (for performance improvements) but if you search for macro name, you should have it surrounded by macro definition +

look at first line to find out which version is it?

@bballer
Copy link
Author

bballer commented Sep 12, 2013

//
// Easylogging++ v9.18
// Single-header only, cross-platform logging library for C++ applications
//
// Author Majid Khan
//

@bballer
Copy link
Author

bballer commented Sep 12, 2013

The most weird thing I found is following: when I put breakpoint at setGlobally(...) it stops there, so nevertheless the macro IS defined it continues to initialize library like without _ELPP_NO_DEFAULT_LOG_FILE macro

#if !defined(_ELPP_NO_DEFAULT_LOG_FILE)
setGlobally(ConfigurationType::Filename, std::string(base::consts::kDefaultLogFile), true);
#else
_ELPP_UNUSED(base::consts::kDefaultLogFile);
#endif // !defined(_ELPP_NO_DEFAULT_LOG_FILE)

@abumq
Copy link
Owner

abumq commented Sep 12, 2013

i can only think the macro namme issue - i would suggest instead of using #define try defining in vstudio config (pre processor settings) so that its defined throughout the app - (if you have multiple source files app)

@bballer
Copy link
Author

bballer commented Sep 12, 2013

Will try, thanks for advice. And thanks for the great lib!

@perone
Copy link

perone commented Oct 10, 2013

I got the same problem, and the root cause is that the file is being created when you call:

_INITIALIZE_EASYLOGGINGPP

So it will always create the default ./logs/myeasylog.log.

@easylogging
Copy link
Contributor

Also worth noticing it's not ELPPNO_DEFAULT_LOG_FILE, it's _ELPP_NO_DEFAULT_LOG_FILE

@Dian8
Copy link

Dian8 commented Nov 8, 2015

In version 9.80 _ELPP_NO_DEFAULT_LOG_FILE changed to ELPP_NO_DEFAULT_LOG_FILE.
It look like other options are also changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants