0

我环顾四周,找不到确切的答案。我正在尝试使用 Pantheios 进行日志记录,并且我想写入外部文件(否则有什么意义)。我正在关注提供的示例之一,但它似乎没有在任何地方制作日志文件。这是代码:

编辑: pantheios_be_file_setFilePath 也返回 -4 (PANTHEIOS_INIT_RC_UNSPECIFIED_FAILURE) 所以那......没有帮助

    #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;
    }

也许我没有调用一个方法,或者它没有被保存到一个好的位置?

4

1 回答 1

0

事实证明,一些泛神论的例子是不正确的。即使您使用 C++,您也需要调用 pantheios_init()。这是我在删除所有代码并实现一个有效的示例后开始工作的示例。

    // 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

我在关于堆栈溢出的另一篇文章中找到了该示例,但就像我说的那样,内置示例不起作用。

于 2014-01-09T13:57:15.880 回答