emilk / loguru

A lightweight C++ logging library
The Unlicense
1.79k stars 260 forks source link

close_file vs17? #95

Closed jamesjrl closed 5 years ago

jamesjrl commented 5 years ago

I was using loguru successfully a few years ago, copmiling for windows using visual studio. I come back to it re-using my old code recently but download the new loguru2.0 and find file_close throws an error I don't understand, and thus far failed to fix.

switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        //Code to run when the DLL is loaded

    /*Initialising threaded log file*/
        loguru::add_file("k:/diffraction1.log", loguru::Append, loguru::Verbosity_MAX);
        loguru::add_file("k:/diffraction2.log", loguru::Append, loguru::Verbosity_INFO);
        LOG_F(INFO, "Hello from dllmain.cpp!");

    case DLL_THREAD_ATTACH:
        // Code to run when a thread is created during the DLL's lifetime

    case DLL_THREAD_DETACH:
        // Code to run when a thread ends normally.

    case DLL_PROCESS_DETACH:
        loguru::file_close("k:/diffraction1.log");
        //loguru::file_close("k:/diffraction2.log");
        break;

and I get the compile error

1>No signal handlers on Win32
dllmain.cpp(27): error C2664: 'void loguru::file_close(void *)': cannot convert argument 1 from 'const char [20]' to 'void *'
dllmain.cpp(27): note: Conversion loses qualifiers

I am slightly out of my depth delaing with this pointer and have failed with multiple tries. While I continue to try to undestand i'd like to check i'm not wasting my time with a deprecated usage as i find nothing in the new documentation regarding file_close

jamesjrl commented 5 years ago

Ok,

change of use of close to now request void pointer, left me stumped for some time. My main error was to concentrate on "fixing" this, when the error was declaring the pointer inside the switch, which throws incompatible type errors no matter what method attempted.

//Define the Log path here
    char logpath[] = "K:/logfile.log"; //Never put this inside the switch, seriously.

    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        //Code to run when the DLL is loaded

    /*Initialising threaded log file*/
        loguru::add_file(logpath, loguru::Append, loguru::Verbosity_INFO);
        LOG_F(INFO, "thread loaded");

    case DLL_THREAD_ATTACH:
        // Code to run when a thread is created during the DLL's lifetime

    case DLL_THREAD_DETACH:
        // Code to run when a thread ends normally.

    case DLL_PROCESS_DETACH:
        //Code to run when the DLL is unloaded.
        loguru::file_close(logpath);
        break;
    }
    return TRUE;
} 

Simple really, issue closed. Some mention of closing the file in the docs might be useful for fellow noobs and code tinkerers.