5

我尝试了 pantheios 的示例来登录到文件,但无法使其工作。消息在控制台中正确显示,但未创建日志文件。自从我看到那个线程以来,我试图改变严重性级别,但没有人工作。

这是代码:

/* Pantheios Header Files */
#include <pantheios/pantheios.hpp>            // Pantheios C++ main header
#include <pantheios/inserters/args.hpp>       // for pantheios::args
#include <pantheios/inserters/exception.hpp>  // for pantheios::exception

#include <pantheios/backends/bec.file.h>      // be.file header

/* Standard C/C++ Header Files */
#include <exception>                          // for std::exception
#include <new>                                // for std::bad_alloc
#include <string>                             // for std::string
#include <stdlib.h>                           // for exit codes

/* ////////////////////////////////////////////////////////////////////// */

/* Define the stock front-end process identity, so that it links when using
* fe.N, fe.simple, etc. */
PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.file");

/* ////////////////////////////////////////////////////////////////////// */

#define PSTR(x)         PANTHEIOS_LITERAL_STRING(x)

/* ////////////////////////////////////////////////////////////////////// */

int main(int argc, char **argv)
{
    try
    {
#ifndef PANTHEIOS_USE_WIDE_STRINGS
        pantheios::log_DEBUG("main(", pantheios::args(argc, argv), ")");
#else /* ? !PANTHEIOS_USE_WIDE_STRINGS */
        STLSOFT_SUPPRESS_UNUSED(argc); STLSOFT_SUPPRESS_UNUSED(argv);
#endif /* !PANTHEIOS_USE_WIDE_STRINGS */

        pantheios::log_NOTICE(PSTR("stmt 1"));

        // Set the file name for the local back-end, truncating the
        // file's existing contents, if any.
        pantheios_be_file_setFilePath(PSTR("log.local"),     PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BE_FILE_F_TRUNCATE, PANTHEIOS_BEID_LOCAL);

        pantheios::log_NOTICE(PSTR("stmt 2"));

        // Set the file name for the remote back-end.
        pantheios_be_file_setFilePath(PSTR("log.remote"), PANTHEIOS_BEID_REMOTE);

        pantheios::log_NOTICE(PSTR("stmt 3"));

        // Set the file name for all back-ends.
        pantheios_be_file_setFilePath(PSTR("log.all"));

    pantheios::log_NOTICE(PSTR("stmt 4"));

    pantheios::log_DEBUG(PSTR("exiting main()"));

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

return EXIT_FAILURE;
}

/* ///////////////////////////// end of file //////////////////////////// */

我有一个“include_pantheios.cpp”文件用于隐式链接目的。这里是 :

/* Pantheios Header Files */
#include <pantheios/implicit_link/core.h>
#include <pantheios/implicit_link/fe.simple.h>
#include <platformstl/platformstl.h>
#include <pantheios/implicit_link/be.file.h>

#if (   defined(UNIX) || \
    defined(unix))&& \
    (   defined(_WIN32) || \
    defined(_WIN64))
# include <unixem/implicit_link.h>
#endif /* _WIN32 || _WIN64 */

有人看到我的问题来自哪里吗?提前致谢,

文森特

4

4 回答 4

4

我认为您的部分困惑来自示例做的太多:它同时显示了本地和远程文件。一个更简单的例子是:

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

int main() {

  pantheios::log_NOTICE("log-1"); // save until log file set
  pantheios_be_file_setFilePath("mylogfile"); // 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"); // sets log file; write "log-3" stmt
  pantheios::log_NOTICE("log-4"); // write "log-4" stmt
} // closes "mylogfile2" during program closedown

我认为来自 Pantheios 示例程序的原始代码的问题在于,它试图说明如何使用本地和远程后端,同时试图说明如何使用 be.file 后端。

忘记所有不同的后端,专注于 be.file 特定的东西。

高温高压

于 2010-11-20T11:01:01.207 回答
3

我遇到了同样的问题,对于未来的人来说,问题是链接库的顺序

Pantheios 论坛: https ://sourceforge.net/projects/pantheios/forums/forum/475314/topic/5313841/index/page/1

我只是在 pantheios.1.be.fprintf.gcc44 之前链接 pantheios.1.be.file.gcc44

于 2012-05-31T07:21:51.670 回答
2

我认为问题在于您链接的顺序,但鉴于您发布的代码,我不太明白它是如何可能的。

我遇到了同样的问题,我意识到这是因为我同时链接了两个后端:file 和 fprintf。更具体地说,这是因为我在文件之前链接了 fprintf。当我先将顺序切换到链接文件时,它会创建并使用日志文件,但当我注释掉 pantheios_be_file_setFilePath 时不会输出到标准输出。所以很明显,首先链接的那个是唯一可以工作的(查找多个后端)。

于 2011-05-22T03:06:17.123 回答
0

据我所知,此代码与库提供的文件库后端示例相同,因此它应该可以工作。

您如何确定未写入日志文件?这些是相对路径 - 尝试使用绝对路径以确保您在正确的位置查找。

如果一切都失败了,您可以通过代码进行调试(在设置文件路径之后)以找出为什么没有写出任何内容。

于 2010-11-19T14:15:24.000 回答