Hi, guys! Using the log4cxx log framework to output log content to the database (MySQL) has not been successful, and I do not know what steps are wrong. I hope everyone can help us or recommend a better log system. thank you. ^_^ --- ** Runtime environment **: Ubuntu12.0432bit + EclipseCDT ** log4cxx **: the apache-log4cxx-0.10.0log4cxx supports two ODBC options (iODBCunixODBC), which are managed in unixODBC form by adding options. co... unixodbcmysqllog4cxx
Hi, guys!
Using the log4cxx log framework to output log content to the database (MySQL) has not been successful, and I do not know what steps are wrong. I hope everyone can help us or recommend a better log system. thank you. Pai_^
Running environment: Ubuntu 12.04 32bit + Eclipse CDT
Log4cxx: Apache-log4cxx-0.10.0
Log4cxx supports two ODBC options (iODBC/unixODBC). here, the unixODBC mode is used for management.
By adding the option./configure -- with-ODBC = unixODBC, the compilation passes.
Then configure the driver and data source of unixODBC.Isql log4cxxConnection established
However, the following error is always reported when Log4cxx is used in the code for output.
log4cxx: Failed to connect to database. - [unixODBC][Driver Manager]Data source name not found, and no default driver specified
Suspect 1:
Whether environment variables are not added to Ecplise;
Check ODBC data and add the ODBCSYSINI, ODBCINSTINI, and ODBCINI variables to Eclipse.
Suspect 2:
The log4cxx configuration is incorrect. Is there any official method!
Configuration content:
/Etc/odbcinst. ini
[MySQL]Description = MySQLDriver = /usr/lib/i386-linux-gnu/odbc/libmyodbc.soSetup = /usr/lib/i386-linux-gnu/odbc/libodbcmyS.soFileUsage = 1
/Etc/odbc. ini
[log4cxx]Description = The Database for Logging SystemTrace = onTraceFile = stderrDriver = MySQLSERVER = localhostPORT = 3306DATABASE = logUSER = root PASSWORD = 56789
Log4cxx. xml
Progress:
_Time: 20150702_
View the Log4cxx source code and record logs in the database mode. the ODBCAppender is used.src/main/cpp/odbcappender.cpp
The author's original code usesSQLxxxW ()Perform DriverConnect and SQLExecDirect operations.WIt adopts Unicode encoding. In short, I keep stuck here and keep reporting that the data source cannot be found. As a resultSQLxxxW()
ModifySQLxxx()
MethodSQLWCHAR
Change to correspondingSQLCHAR
That is, a non-width byte operation is used to successfully locate the data source and call the data source.
However, this causes Chinese problems.
Doubt
The Driver configured in odbcinst. ini is indeed libmydbc5w. so, that is, the Driver uses Unicode! (* Corresponds to libmydbc5a. so *). so far, I still don't know where I am going wrong. it is impossible for the author to use SQLxxxW () for ODBC Connection without any justification.
I added
# Define SQL _WCHART_CONVERT
#if !defined(LOG4CXX)#define LOG4CXX 1#endif#include
#if LOG4CXX_HAVE_ODBC#if defined(WIN32) || defined(_WIN32)#include
#endif#define SQL_WCHART_CONVERT#include
#endif