logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sorin POPA <sorro...@yahoo.com>
Subject Building and using log4cxx 0.9.8 on Visual Studio 2003...
Date Mon, 27 Nov 2006 14:11:06 GMT
Hello, friends!



Mi amigos and I are trying to use log4cxx in a Visual C++ project, in Visual Studio 2003.

We have built the library with Ant (following the indications in the INSTALL guide) and we
can use it now.

Still we have some questions, which may find answers here.



So, here are the facts!


What IS WORKING:

----------------------------------------------------------------------------------

main.cpp
----------
#include <log4cxx/logger.h>
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/helpers/exception.h>
#include <iostream>

int main(int argc, char **argv)
{
    try
    {
        log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("main"));
        log4cxx::xml::DOMConfigurator::configure("log4cxx.xml");
        LOG4CXX_DEBUG(logger, "Debug message");
        LOG4CXX_INFO(logger, "Info message");
        LOG4CXX_WARN(logger, "Warn message");
        LOG4CXX_ERROR(logger, "Error message");
        LOG4CXX_FATAL(logger, "Fatal error");
        LOG4CXX_ASSERT(logger, 1 == 2, "Assertion false");
        return 0;
    }
    catch (const log4cxx::helpers::Exception & exception)
    {
        std::cerr << "log4cxx::helpers::Exception caught - original message: " <<
exception.what() << std::endl;
        return 1;
    }
}


log4cxx.xml
-------------
<?xml version="1.0" encoding="UTF-8"?>
http://jakarta.apache.org/log4j/' debug="false">
    <appender name="DRFA" class="org.apache.log4j.rolling.RollingFileAppender">
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern" value="C:\server.%d{yyyyMMdd}.log"/>
        </rollingPolicy>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss.SSS} [%-5p] %c{1} - %m%n"/>
        </layout>
        <param name="Append" value="true"/>
    </appender> 
    <root>
        <level value="DEBUG"/>
        <appender-ref ref="DRFA"/>
    </root>
</log4j:configuration>

server.20061127.log
-----------------------
12:14:04.758 [DEBUG] main - Debug message
12:14:04.758 [INFO ] main - Info message
12:14:04.758 [WARN ] main - Warn message
12:14:04.758 [ERROR] main - Error message
12:14:04.758 [FATAL] main - Fatal error
12:14:04.758 [ERROR] main - Assertion false

This is the way we're going to use log4cxx.



What IS NOT WORKING:
----------------------------------------------------------------------------------

main.cpp
----------
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>

//#include <log4cxx/log4cxx.h>
#include <log4cxx/logger.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/simplelayout.h>
#include <log4cxx/patternlayout.h>
#include <log4cxx/consoleappender.h>
#include <log4cxx/writerappender.h>
#include <log4cxx/fileappender.h>
#include <log4cxx/rollingfileappender.h>
#include <log4cxx/dailyrollingfileappender.h>
#include <log4cxx/helpers/stringhelper.h>

using namespace std;
using namespace log4cxx;
using namespace log4cxx::helpers;

int _tmain(int argc, _TCHAR* argv[])
{
    LoggerPtr logger (Logger::getLogger(L"main"));
    LayoutPtr  pl       (new PatternLayout(L"%d{ABSOLUTE} [%t] %level %c{2}#%M:%L - %m%n"));
    

    DailyRollingFileAppenderPtr drfa(new DailyRollingFileAppender());
    drfa->setName(L"DRFA");
    drfa->setLayout(pl);
    drfa->setDatePattern(L"yyyy-MM-dd_HH_mm_ss");
    drfa->setFile(L"OblioDRFA.log");
    drfa->activateOptions();

    logger->addAppender(drfa);

    LOG4CXX_DEBUG (logger, "Debug message");

    return 0;
}

No configuration file for log4cxx
------------------------------------

The build output is:
----------------------
Linking...
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall
log4cxx::Logger::forcedLog(class log4cxx::helpers::ObjectPtrT<class log4cxx::Level>
const &,class std::basic_string<unsigned short,struct std::char_traits<unsigned
short>,class std::allocator<unsigned short> > const &,char const *,int)" (__imp_?forcedLog@Logger@log4cxx@@QAEXABV?$ObjectPtrT@VLevel@log4cxx@@@helpers@2@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@PBDH@Z)
referenced in function _wmain
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall
log4cxx::FileAppender::setFile(class std::basic_string<unsigned short,struct std::char_traits<unsigned
short>,class std::allocator<unsigned short> > const &)" (__imp_?setFile@FileAppender@log4cxx@@QAEXABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
referenced in function _wmain
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall
log4cxx::DailyRollingFileAppender::setDatePattern(class std::basic_string<unsigned short,struct
std::char_traits<unsigned short>,class std::allocator<unsigned short> > const
&)" (__imp_?setDatePattern@DailyRollingFileAppender@log4cxx@@QAEXABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
referenced in function _wmain
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall
log4cxx::PatternLayout::PatternLayout(class std::basic_string<unsigned short,struct std::char_traits<unsigned
short>,class std::allocator<unsigned short> > const &)" (__imp_??0PatternLayout@log4cxx@@QAE@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
referenced in function _wmain
main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static
class log4cxx::helpers::ObjectPtrT<class log4cxx::Logger> __cdecl log4cxx::Logger::getLogger(class
std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned
short> > const &)" (__imp_?getLogger@Logger@log4cxx@@SA?AV?$ObjectPtrT@VLogger@log4cxx@@@helpers@2@ABV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z)
referenced in function _wmain
Debug/main.exe : fatal error LNK1120: 5 unresolved externals

We get this output, even though we have the log4cxxd.lib file included, and besides - checking
the contents of the lib - we observe the declarations that the builder announces as missing
in the message above.
We made several attempts to get something working this way, but with the same results.
We don't understand why this is happening.

We've checked many forums before posting this and tryied many times to make it work.
It seems that there were some more similar events - such messages with   unresolved external
symbol "__declspec(dllimport).... but no answers yet.

However, this is NOT the approach we'll take in using log4cxx in the project, but we would
appreciate if you can give some answers to us.


ONE MORE THING TO MENTION:
-------------------------------------
We didn't manage, using the Ant way, to build the release version of the log4cxx dll and lib.
The options for doing this are there with Ant, but we didn't get the expected result.

If you have time, please look into these.
Thanks, amigos!

I wish you all a great day!


Sorin Popa

Romania
Mobile:    +40 728 030299





 
____________________________________________________________________________________
Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index

Mime
View raw message