Pantheios write to extenal file
Asked Answered
I

1

0

I looked around and I couldn't find the answer to how exactly to do this. I am trying to use Pantheios for logging and I want to write to an external file (otherwise whats the point). I am following one of the examples provided but It doesn't seem to be making the log file anywhere. Here is the code:

Edit: Also pantheios_be_file_setFilePath is returning -4 (PANTHEIOS_INIT_RC_UNSPECIFIED_FAILURE) so thats.....not helpful

    #include "stdafx.h"
    #include <pantheios/pantheios.hpp> 
    #include <pantheios/implicit_link/core.h>
    #include <pantheios/implicit_link/fe.simple.h> 
    #include <pantheios/implicit_link/be.WindowsConsole.h>
    #include <pantheios/implicit_link/be.file.h>
    #include <pantheios/frontends/fe.simple.h>
    #include <pantheios/backends/bec.file.h>
    #include <pantheios/inserters/args.hpp>

    PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("LogTest");

    int _tmain(int argc, _TCHAR* argv[])
    {
        try
        {
            pantheios_be_file_setFilePath(PANTHEIOS_LITERAL_STRING("testlogforme.log"),  PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BEID_ALL);


            pantheios::log(pantheios::debug, "Entering main(", pantheios::args(argc,argv, pantheios::args::arg0FileOnly), ")");

            pantheios::log_DEBUG("debug yo");
            pantheios::log_INFORMATIONAL("informational fyi");
            pantheios::log_NOTICE("notice me!");
            pantheios::log_WARNING("warning!!");
            pantheios::log_ERROR("error omg");
            pantheios::log_CRITICAL("critical!!!");
            pantheios::log_ALERT("alert mang");
            pantheios::log_EMERGENCY("EMERGENCY!!!!!");

            pantheios_be_file_setFilePath(NULL, PANTHEIOS_BEID_ALL);

            system("pause");
            return EXIT_SUCCESS;
        }
        catch(std::bad_alloc&)
        {
            pantheios::log_ALERT("out of memory");
        }
        catch(std::exception& x)
        {
            pantheios::log_CRITICAL("Exception: ", x);
        }
        catch(...)
        {
            pantheios::puts(pantheios::emergency, "Unexpected unknown error");
        }

        return EXIT_FAILURE;
    }

Maybe I'm not calling a method or maybe its not being saved to a good location?

Interracial answered 8/1, 2014 at 14:24 Comment(1)
I guess the examples provided are incorrect.Interracial
I
0

It turns out that some of the examples out there for pantheios are incorrect. You DO need to call pantheios_init() even if you are in C++. Here Is the example I got to work after deleting all my code and implementing an example that works.

    // Headers for main()
    #include <pantheios/pantheios.hpp> 
    #include <pantheios/backends/bec.file.h> 

    // Headers for implicit linking
    #include <pantheios/implicit_link/core.h>
    #include <pantheios/implicit_link/fe.simple.h>
    #include <pantheios/implicit_link/be.file.h>

    PANTHEIOS_EXTERN_C const char PANTHEIOS_FE_PROCESS_IDENTITY[] = "testLOL";

    int main()
    {
        if(pantheios::pantheios_init() < 0)
        {
            return 1;
        }

        pantheios::log_NOTICE("log-1"); // save until log file set
        pantheios_be_file_setFilePath("mylogfile.log"); // sets log file; write "log-1" stmt
        pantheios::log_NOTICE("log-2"); // write "log-2" stmt
        pantheios_be_file_setFilePath(NULL); // close "mylogfile"


        pantheios::log_NOTICE("log-3"); // save until log file set
        pantheios_be_file_setFilePath("mylogfile2.log"); // sets log file; write "log-3" stmt
        pantheios::log_NOTICE("log-4"); // write "log-4" stmt

        //system("pause");
        return 0;
    } // closes "mylogfile2" during program closedown

I found the example on a different post on stack overflow but like I said, the built in examples do not work.

Interracial answered 9/1, 2014 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.