Git Product home page Git Product logo

Comments (7)

wilx avatar wilx commented on June 16, 2024

You can do that by redefining the LOG4CPLUS_MACRO_FUNCTION() function macro. The sequence should be something like this:

#include <log4cplus/loggingmacros.h>
#undef LOG4CPLUS_MACRO_FUNCTION
#define LOG4CPLUS_MACRO_FUNCTION() __FUNCTION__

Undef and define the macro after the loggingmacros.h has been included.

from log4cplus.

Devlooper8 avatar Devlooper8 commented on June 16, 2024

Thank you, yeah this fulfills my requirements.

from log4cplus.

Devlooper8 avatar Devlooper8 commented on June 16, 2024

This works when I have this library as shared, but when I try it as a static library, no matter what I do, the default 'PRETTY_FUNCTION' is still used. I can't change it even when I redefine that macro. It does nothing. I also tried editing the config and defines.hxx in includes, but 'PRETTY_FUNCTION' is still set as the default. I want to change it to FUNCTION. Another question: wouldn't it be better to have another flag in the configurator that differentiates between 'func', FUNCTION, and PRETTY_FUNCTION? It would be easier to configure.

I am using latest version of log4cplus.

from log4cplus.

wilx avatar wilx commented on June 16, 2024

It is a macro, it is active where it is used. If you compile the code that uses the macro into a binary or a library, you can't change it afterwards.

from log4cplus.

Devlooper8 avatar Devlooper8 commented on June 16, 2024

I have found it the hard way, but I would need to set the function macro persistently to FUNCTION but when i tried to redefine that config.hxx and defines.hxx before compilation still PRETTY_FUNCTION was used

from log4cplus.

wilx avatar wilx commented on June 16, 2024

You have to use it in the way I have shown:

#include <log4cplus/loggingmacros.h>
#undef LOG4CPLUS_MACRO_FUNCTION
#define LOG4CPLUS_MACRO_FUNCTION() __FUNCTION__

You cannot do it any other way.

from log4cplus.

Devlooper8 avatar Devlooper8 commented on June 16, 2024

"I think we don't understand each other. This is an example program.

#include <log4cplus/initializer.h>
#include <log4cplus/logger.h>
#include <log4cplus/configurator.h>

#include <log4cplus/loggingmacros.h>
#undef LOG4CPLUS_MACRO_FUNCTION
#define LOG4CPLUS_MACRO_FUNCTION() __FUNCTION__

using namespace std;
using namespace log4cplus;
using namespace log4cplus::helpers;

int main(const int argc, char* argv[]) {
    Initializer initializer;
    Logger root = Logger::getRoot();
    PropertyConfigurator::doConfigure("log4cplus.properties");

    LOG4CPLUS_WARN(root, "Modem timeout");

    return 0;
}

No matter what I define on that macro FUNCTION PRETTY_FUNCTION func, the output is always like this:

[WARN ] 2024-02-03 08:20:34 (main.cpp: int main(int, char**)) 46: Modem timeout

When I had this library as a .so, everything worked correctly. However, when I try to use it as a .a library, it doesn't work."

expected output will be something like this:

[WARN ] 2024-02-03 08:20:34 (main.cpp: main) 46: Modem timeout

from log4cplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.