ปลั๊กอิน Firebreath NPAPI วิธีการบันทึก

วิธีส่งข้อความบันทึกด้วยปลั๊กอิน NPAPI ที่สร้างด้วย FireBreath ใน C++
บันทึกควรจะพร้อมใช้งานในระหว่างการพัฒนาและการทดสอบ และ/หรือในรุ่น Debug


แก้ไขแล้ว:

วิธีบันทึกของ FireBreath คือ Log4cplus และฉันได้พยายามที่จะนำไปใช้อย่างใกล้ชิดกับ ฉันทำตามคำแนะนำเหล่านี้ได้
ฉันเพิ่ม add_firebreath_library(log4cplus) ไว้ที่ด้านล่างของ "PluginConfig.cmake"

ฉันยังไม่สามารถสร้างไฟล์บันทึกที่สามารถอ่านบน Windows 8 ได้ ฉันได้เรียกดูผ่านแหล่งข้อมูลอื่น ๆ เช่น: FBLOG_TRACE() ไม่มีการบันทึกไปยัง Logfile -- FBLOG_INFO() การบันทึกตกลง -- อะไรคือความแตกต่าง

จนถึงตอนนี้ ความพยายามในการบันทึกทั้งหมดของฉันมีดังนี้:

#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 ใน "PluginConfig.cmake" ด้วย add_firebreath_library(log4cplus) ฉันได้รับข้อความ "not found" " ข้อผิดพลาดในสคริปต์ prep ของฉันบน Windows แต่สคริปต์ดูเหมือนจะเสร็จสมบูรณ์แล้ว และปลั๊กอินของฉันก็สร้างได้โดยไม่มีข้อผิดพลาด ดังนั้นฉันจึงเลือกที่จะเพิกเฉยต่อข้อผิดพลาดเหล่านี้ แต่นี่คือ:

หมายเหตุ: การแทนที่เส้นทางบางส่วนด้วย '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: ซาฟารี และ Chrome
  2. Windows: IE 10 และ Chrome

FWIW: การติดตั้ง My Win เพื่อการพัฒนาอยู่ใน Mac VMWare Fusion v5.0 Guest

สรุป:

โปรดช่วยฉันให้ Log4cplus ทำงานในปลั๊กอินของฉันด้วยไฟล์บันทึกที่สามารถเข้าถึงได้


person David Manpearl    schedule 01.04.2013    source แหล่งที่มา


คำตอบ (1)


ดูเหมือนว่าคุณมาถูกทางแล้ว แต่คุณพลาดส่วนที่สำคัญมากไป คุณไม่สามารถเขียนถึง C:\logs ได้ เนื่องจากมีเพียงผู้ดูแลระบบเท่านั้นที่มีสิทธิ์ในการดำเนินการดังกล่าว

สำหรับข้อผิดพลาด "ไม่พบ" นั้น ไม่ใช่ข้อผิดพลาด... เป็นเพียงข้อความสถานะ นั่นเป็นส่วนหนึ่งของการสร้าง log4cplus โดยเพื่อดูว่าแพลตฟอร์มของคุณรองรับอะไรบ้าง คุณสามารถเพิกเฉยต่อสิ่งเหล่านั้นได้อย่างปลอดภัย

หากคุณดูที่หน้า เคล็ดลับและคำแนะนำ คุณจะพบ ตัวอย่างที่เป็นประโยชน์

ส่วนสำคัญที่ฉันอ้างถึงนั้นมาจาก จากส่วนสำคัญที่ฉันสร้างขึ้นในสมัยก่อน; คุณจะต้อง add_boost_library(filesystem) แต่คุณสามารถใช้รหัสนี้เพื่อค้นหาตำแหน่งที่ถูกต้องเพื่อใส่บันทึกของคุณ ขณะนี้รหัสตรวจพบว่าเส้นทางบันทึก (ซึ่งจะอยู่ใน %AppData%\LocalLow\CompanyName\logs ด้วย รหัสนี้) มีอยู่และเขียนบันทึกเฉพาะในกรณีที่มีเท่านั้น นอกจากนี้ยังใช้การประทับเวลาและรหัสกระบวนการเพื่อให้แน่ใจว่าอินสแตนซ์ปลั๊กอินไม่ซ้ำกัน

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


// ...
person taxilian    schedule 02.04.2013
comment
แล้วลินุกซ์ล่ะ? - person kangear; 27.10.2019
comment
เมื่อมาถึงจุดนี้ฉันจำไม่ได้ มีโอกาสดีที่มันจะทำงานบน linux ได้เช่นกันเนื่องจากฉันคิดว่าฟังก์ชัน getLocalAppDataPath ก็ทำงานบน linux ได้เช่นกัน - person taxilian; 30.10.2019