c++ - Firebreath NPAPI 插件如何登录

标签 c++ npapi firebreath browser-plugin log4cplus

如何使用在 C++ 中使用 FireBreath 构建的 NPAPI 插件输出日志消息
日志应该在开发和测试期间和/或调试构建期间可用。


修改:

FireBreath 的记录方式是 Log4cplus ,并且我已尝试尽可能严格地执行这些说明。
我将 add_firebreath_library(log4cplus) 附加到“PluginConfig.cmake”的底部。

我还不能创建一个我可以在 Windows 8 上阅读的日志文件。我浏览了其他资源,例如:FBLOG_TRACE() No logging to Logfile -- FBLOG_INFO() logging OK -- What is the DIFFERENCE

到目前为止,我所有的日志记录尝试如下:

#include "logging.h"
...
FBLOG_INFO("my function name", "and some text");

可选调试级别:

我不确定是否必须覆盖 getLogLevel(),因为我对 INFO 的默认级别很满意,但我不确定究竟是什么 如果我覆盖它,把它放在哪里:

FB::Log::LogLevel getLogLevel(){
    return FB::Log::LogLevel_Trace; // Now Trace and above is logged.
}

日志文件路径:

我也不确定在 Windows 中写入日志文件的正确路径。我试过:

- outMethods.push_back(std::make_pair(FB::Log::LogMethod_File, "C:/logs/XXXX/yyyy.log"));
- outMethods.push_back(std::make_pair(FB::Log::LogMethod_File, "C:\logs\XXXX\yyyy.log"));
- outMethods.push_back(std::make_pair(FB::Log::LogMethod_File, "/logs/XXXX/yyyy.log"));
etc.

准备脚本错误:

启用Log4cplus之后在带有 add_firebreath_library(log4cplus) 的“PluginConfig.cmake”中,我在 Windows 上的 prep 脚本中遇到一些“未找到”错误,但脚本似乎成功完成,而且我的插件构建没有错误,所以到目前为止我选择忽略这些错误。但是,它们在这里:

注意:部分路径替换为“XXXXX”。

Z:\XXXXX\firebreath>firebreath-dev\prep2010.cmd projects fbbuildwin
A subdirectory or file fbbuildwin already exists.
Using projects in: "Z:\XXXXX\firebreath\projects"
Generating build files in: "Z:\XXXXX\firebreath\fbbuildwin"
NOTE: The build files in "Z:\XXXXX\firebreath\fbbuildwin" should *NEVER* be modified directly.
When needed, make project changes in cmake files and re-run this script.
  Project-specific cmake files are found in [plugin dir]\CMakeLists.txt and
  [plugin dir]\Win\projectDef.cmake.
Note that parameters for cmake should be enclosed in double quotes, e.g. "-DVERBOSE=1"
CMAKE parameters:
Z:\XXXXX\firebreath\fbbuildwin>cmake -G "Visual Studio 10" -DFB_PROJECTS_DIR="Z:\dmanpearl On My Mac\pixelmonks\LaasTech\firebreath\projects"  "Z:\XXXXX\firebreath\firebreath-dev"
-- Balanced size/speed optimization project dir: Z:/XXXXX/firebreath/projects
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found
-- Found Threads: TRUE
-- Threads:
-- Looking for include file dlfcn.h
-- Looking for include file dlfcn.h - not found
-- Looking for include file errno.h
-- Looking for include file errno.h - found
-- Looking for include file iconv.h
-- Looking for include file iconv.h - not found
-- Looking for include file limits.h
-- Looking for include file limits.h - found
-- Looking for include file sys/types.h
-- Looking for include file sys/types.h - found
-- Looking for include file sys/socket.h
-- Looking for include file sys/socket.h - not found
-- Looking for include file sys/syscall.h
-- Looking for include file sys/syscall.h - not found
-- Looking for include file sys/time.h
-- Looking for include file sys/time.h - not found
-- Looking for include file sys/timeb.h
-- Looking for include file sys/timeb.h - found
-- Looking for include file sys/stat.h
-- Looking for include file sys/stat.h - found
-- Looking for include file sys/file.h
-- Looking for include file sys/file.h - not found
-- Looking for include file syslog.h
-- Looking for include file syslog.h - not found
-- Looking for include file arpa/inet.h
-- Looking for include file arpa/inet.h - not found
-- Looking for include file netinet/in.h
-- Looking for include file netinet/in.h - not found
-- Looking for include file netinet/tcp.h
-- Looking for include file netinet/tcp.h - not found
-- Looking for include file netdb.h
-- Looking for include file netdb.h - not found
-- Looking for include file unistd.h
-- Looking for include file unistd.h - not found
-- Looking for include file fcntl.h
-- Looking for include file fcntl.h - found
-- Looking for include file stdio.h
-- Looking for include file stdio.h - found
-- Looking for include file stdarg.h
-- Looking for include file stdarg.h - found
-- Looking for include file stdlib.h
-- Looking for include file stdlib.h - found
-- Looking for include file time.h
-- Looking for include file time.h - found
-- Looking for include file wchar.h
-- Looking for include file wchar.h - found
-- Looking for include file inttypes.h
-- Looking for include file inttypes.h - not found
-- Looking for include file memory.h
-- Looking for include file memory.h - found
-- Looking for include file stdint.h
-- Looking for include file stdint.h - found
-- Looking for include file strings.h
-- Looking for include file strings.h - not found
-- Looking for include file string.h
-- Looking for include file string.h - found
-- Looking for 5 include files stdlib.h, ..., float.h
-- Looking for 5 include files stdlib.h, ..., float.h - found
-- Looking for gmtime_r
-- Looking for gmtime_r - not found
-- Looking for localtime_r
-- Looking for localtime_r - not found
-- Looking for gettimeofday
-- Looking for gettimeofday - not found
-- Looking for getpid
-- Looking for getpid - found
-- Looking for ftime
-- Looking for ftime - found
-- Looking for stat
-- Looking for stat - found
-- Looking for lstat
-- Looking for lstat - not found
-- Looking for fcntl
-- Looking for fcntl - not found
-- Looking for lockf
-- Looking for lockf - not found
-- Looking for flock
-- Looking for flock - not found
-- Looking for htons
-- Looking for htons - not found
-- Looking for ntohs
-- Looking for ntohs - not found
-- Looking for htonl
-- Looking for htonl - not found
-- Looking for ntohl
-- Looking for ntohl - not found
-- Looking for vsnprintf
-- Looking for vsnprintf - found
-- Looking for _vsnprintf
-- Looking for _vsnprintf - found
-- Looking for vsprintf_s
-- Looking for vsprintf_s - found
-- Looking for vswprintf_s
-- Looking for vswprintf_s - found
-- Looking for vfprintf_s
-- Looking for vfprintf_s - found
-- Looking for vfwprintf_s
-- Looking for vfwprintf_s - found
-- Looking for _vsnprintf_s
-- Looking for _vsnprintf_s - found
-- Looking for _vsnwprintf_s
-- Looking for _vsnwprintf_s - found
-- Looking for mbstowcs
-- Looking for mbstowcs - found
-- Looking for wcstombs
-- Looking for wcstombs - found
-- Looking for ENAMETOOLONG
-- Looking for ENAMETOOLONG - found
-- Looking for SYS_gettid
-- Looking for SYS_gettid - not found
-- Looking for __FUNCTION__
-- Looking for __FUNCTION__ - found
-- Looking for __PRETTY_FUNCTION__
-- Looking for __PRETTY_FUNCTION__ - not found
-- Looking for __func__
-- Looking for __func__ - not found
-- Performing Test LOG4CPLUS_HAVE___SYNC_ADD_AND_FETCH
-- Performing Test LOG4CPLUS_HAVE___SYNC_ADD_AND_FETCH - Failed
-- Performing Test LOG4CPLUS_HAVE___SYNC_SUB_AND_FETCH
-- Performing Test LOG4CPLUS_HAVE___SYNC_SUB_AND_FETCH - Failed
-- Performing Test LOG4CPLUS_HAVE_GNU_VARIADIC_MACROS
-- Performing Test LOG4CPLUS_HAVE_GNU_VARIADIC_MACROS - Failed
-- Performing Test LOG4CPLUS_HAVE_C99_VARIADIC_MACROS
-- Performing Test LOG4CPLUS_HAVE_C99_VARIADIC_MACROS - Success
-- Looking for clock_gettime
-- Looking for clock_gettime - not found
-- Looking for clock_nanosleep
-- Looking for clock_nanosleep - not found
-- Looking for nanosleep
-- Looking for nanosleep - not found
-- Looking for gethostbyname_r
-- Looking for gethostbyname_r - not found
-- Looking for getaddrinfo
-- Looking for getaddrinfo - not found
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY
-- Performing Test HAVE_ATTRIBUTE_VISIBILITY - Failed
-- Performing Test HAVE_DECLSPEC_DLLEXPORT
-- Performing Test HAVE_DECLSPEC_DLLEXPORT - Success
-- Performing Test HAVE_CXX11_THREAD_LOCAL
-- Performing Test HAVE_CXX11_THREAD_LOCAL - Failed
-- Performing Test HAVE_GCC_THREAD_EXTENSION
-- Performing Test HAVE_GCC_THREAD_EXTENSION - Failed
-- Performing Test HAVE_DECLSPEC_THREAD
-- Performing Test HAVE_DECLSPEC_THREAD - Success
-- Performing Test LOG4CPLUS_HAVE_CXX11_ATOMICS
-- Performing Test LOG4CPLUS_HAVE_CXX11_ATOMICS - Failed
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of socklen_t
-- Check size of socklen_t - failed
Adding library log4cplus
Generating plugin configuration files in Z:/XXXXX/firebreath/fbbuildwin/projects/LaasTech/gen
-- Configuring done
-- Generating done
-- Build files have been written to: Z:/XXXXX/firebreath/fbbuildwin

我的环境:

我目前正在 Mac 和 Windows(Mountain Lion 和 Windows 8)上构建我的插件。

我正在以下浏览器中进行测试:

  1. Mac:Safari 和 Chrome。
  2. Windows:IE 10 和 Chrome。

FWIW:我用于开发的 Win 安装在 Mac VMWare Fusion v5.0 Guest 中。

总结:

请帮助我使用可访问的日志文件让 Log4cplus 在我的插件中工作。

最佳答案

看起来您在正确的轨道上,但您遗漏了一个非常重要的部分——您不能写入 C:\logs,因为只有管理员才有权执行此操作。

至于“未找到”“错误”,那些不是错误……只是状态消息。这是构建 log4cplus 的一部分,它正在查看您的平台支持什么。您可以安全地忽略这些。

如果您查看 Tips and Tricks页面你会发现一些useful examples .

我指的主要是 from a gist I created some time back ;你需要 add_boost_library(filesystem) 但你可以使用此代码找到一个有效的位置来放置你的日志。该代码当前检测日志路径(将位于 %AppData%\LocalLow\CompanyName\logs 与此代码)存在并且仅在存在时才写入日志。它还使用时间戳和进程 ID 来确保插件实例的唯一性。

#include <boost/filesystem.hpp>
#include "SystemHelpers.h"
using namespace boost::filesystem;

/// ...


void getLoggingMethods( FB::Log::LogMethodList& outMethods )
{
    path appDataPath = FB::System::getLocalAppDataPath("CompanyName");

    path logDirPath = appDataPath / "logs";
    if (exists(logDirPath) && is_directory(logDirPath)) {
        std::stringstream ss;
        time_t seconds = time(NULL);
        boost::thread::id threadId = boost::this_thread::get_id();
        ss << seconds << "_" << threadId << ".log";

        path logPath = logDirPath / ss.str();

        fprintf(stderr, "logging to %s", logPath.string().c_str());
        outMethods.push_back(std::make_pair(FB::Log::LogMethod_File, logPath.string()));
    }
#ifndef NDEBUG
    outMethods.push_back(std::make_pair(FB::Log::LogMethod_Console, std::string()));
#endif
}


// ...

关于c++ - Firebreath NPAPI 插件如何登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15746407/

相关文章:

google-chrome - 从 chrome 浏览器启动我安装的应用程序

css - 在 Webkit 中更改其 'position' 样式属性时删除的插件实例

c++ - 调用 QGLWidget::setFormat = 无绘图

c++ - 我有一个具有不同前缀的相关函数的 C 库。派生的 C++ 类如何在不重复代码的情况下调用它们?

java - Opera for Windows(NPAPI 插件)中是否禁用了 Java?

c++ - Firebreath 不会使用 Xcode 5.0.2 进行编译

c++ - 如何从 JSAPI 端设置插件对象的边框和其他样式?

c++ - Firebreath OpenGl 窗口闪烁

c++ - 使用 sfinae 启用/禁用 typedef 是不可能的。解决方法?

c++ - 在循环中创建对象并将其添加到 vector 时,总是添加相同的对象