abumq / easyloggingpp

C++ logging library. It is powerful, supports asynchronous low latency, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
MIT License
3.76k stars 918 forks source link

'logs' directory is made automatically #99

Closed aszkid closed 11 years ago

aszkid commented 11 years ago

I've been playing around and have noticed that, no matter if my configuration specifically defines a file as follows:

    * GLOBAL:
        FORMAT               =  "%datetime %log"
        FILENAME             =  "../my.log"
        ENABLED              =  true
        TO_FILE              =  true
        TO_STANDARD_OUTPUT   =  true
        MILLISECONDS_WIDTH   =  6
        PERFORMANCE_TRACKING =  true
        MAX_LOG_FILE_SIZE    =  2097152
    * DEBUG:
        FORMAT               = "%datetime{%d/%M/%Y %h:%n:%s} %log"

A folder 'logs' and empty file 'myeasylog.log' is made (inside the folder). Is that supposed to happen? Is there any way to avoid the creation of the folder and file?

easylogging commented 11 years ago

Hey,

Yup there is a way to avoid it - or more specifically to change it - this is necessary as this is the starting configuration (and then when you re-configure, it just re-assigns it)

The way you change it is macro definition during compilation or above #include "easylogging++.h"

Macro name is _ELPP_DEFAULT_LOG_FILE and value will be filepath you want, (may be /tmp/my-tmp-file.log?) Have a look at the last macro on Configuration Macros section.

PLease let me know if you can think of any alternative way of implementation :)

EDIT: And you have typo in DEBUG date format, i think you need %m :) instead of %n hope this helps

easylogging commented 11 years ago

I have come up with a solution to this and will implement this in v9.13

easylogging commented 11 years ago

Fixed in v9.13 :) - look for macro name _ELPP_NO_DEFAULT_LOG_FILE in Configuration Macros section of manual

feel free to check out release notes for v9.12 (released yesterday) and v9.13

aszkid commented 11 years ago

Thanks for you attention and the feature addition, but i'm getting an assertion with the expression 'map/set iterator not dereferencable' right when the debugger steps over _INITIALIZE_EASYLOGGINGPP. Something's wrong, because if i remove the definition of the macro _ELPP_NO_DEFAULT_LOG_FILE, it works, but it (obviously) creates the folder and log file.

error

I'll spend some time and go over the easylogging file, to see if i can help to correct bugs as i encounter them. Thanks a lot for your hard work!

easylogging commented 11 years ago

All good :)

Sorry about that, try v9.14 and let me know if this issue is still there - currently i am travelling so I cant test on my windows machine

easylogging commented 11 years ago

Also if you are worried about compile warnings - they have been fixed in v9.15

easylogging commented 11 years ago

Confirmed - its working with VC++ (and other compilers) provided you dont try to log before configuration

aszkid commented 11 years ago

Ugh, then i'm doing something wrong, because with 9.16 i still get that assertion error:

ohnoes

easylogging commented 11 years ago

I retried with the code in your screenshot and my guess is your configuration file path is not correct- please find two attachments, one with invalid path where i do get assertion failure (as expected because I am trying to write to file that does not yet exist hence not pointer to it is not derefernecable) and other with correct configuration path which works good invalid-path correct-path

Try it with fully qualified path

or alternatively using

el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Filename, "../my.log"); before you start logging anything including CHECK macros

easylogging commented 11 years ago

I tried relative path and it works for me as well - e.g, in VC++ sample \samples\VC++\VCPP2012_Win32_Multithreaded I put my configuration file there and used same relative path as yours with my file conf.txt and its logging to correct place and picking up from correct place

I think to be on safe side always use el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Filename, "../my.log"); before trying to configure using configuration file, that way you will always know if it can't find configuratoin file - it will log to my.log anyway

easylogging commented 11 years ago

I have created issue https://github.com/easylogging/easyloggingpp/issues/102 for v9.17 release

aszkid commented 11 years ago

This is weird:

what

If i take the NO_DEFAULT_LOG_FILE macro out, it works.

easylogging commented 11 years ago

Well it is weird. Can u plz make sure u have at least v9.15 if not any higher? You can see it from top of header file

easylogging commented 11 years ago

And one more thinn u have braces around easylogging ++ header which means the preferred search path is include path. Can u plz make sure when u look for version u look at correct file thst vs2012 is picking up