Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Logging Library Setup

I've been trying for about 2 weeks now to get a logging library to work with. I've tried Log4cxx, Log4cpp, log4cplus and boost.log. The problem isn't that none of these work for me, it's that I can't figure out how to get them to work at all. I would really like to use log4cxx since I'm working with log4j/logback at work, but I haven't been able to get any of the libraries based on log4j to build. I've been able to build and use the boost library, but boost.log gives me all kinds of linker errors no matter what I try. If anyone could direct me to a step-by-step guide to get one of these libraries working I would greatly appreciate it. Also, I'm using eclipse as my IDE if that matters.

like image 241
Shenlong55 Avatar asked Feb 01 '11 02:02

Shenlong55


People also ask

How to Set Logger in c#?

Each file is written by a separate logger, so you need to use both inside of your code: ILog Log = LogManager. GetLogger(typeof(LogTest)); ILog ErrorLog = LogManager. GetLogger("error"); Log.Info("Debug message"); ErrorLog.

What is a logging library?

A logging library (or logging framework) is code that you embed into your application to create and manage log events. Logging libraries provide APIs for creating, structuring, formatting, and transmitting log events in a consistent way. Like agents, they're used to send events from your application to a destination.

How to log Error in c#?

GetCurrentClassLogger(); // creates a logger using the class name // use it: logger.Info(...); logger. Error(...); // and also: logger. ErrorException("text", ex); // which will log the stack trace. One additional note if using error.


2 Answers

Did you ever get this working? Log4cxx definitely works on Win7. Maybe you could post some of your build errors. Just guessing, perhaps you didn't configure your eclipse project to link with a log4cxx static lib.

like image 75
David Grigsby Avatar answered Sep 30 '22 01:09

David Grigsby


Boost.Log works for me quite well (Linux and Windows). It is not a header only library, there is a compiled part that you need to link against. See instructions here.

It also depends on other, non-header, Boost libraries:

The logging library uses several other Boost libraries that need building too. These are Boost.Filesystem, Boost.System, Boost.DateTime, Boost.Thread and Boost.Regex. Refer to their documentation for detailed instructions on the building procedure.

Depending on your platform there may be pre-built versions of the Boost libraries. Otherwise building it yourself is straightforward if you follow the instructions. If you get stuck update your question with where exactly you got stuck and what you're seeing.

like image 23
Guy Sirton Avatar answered Sep 30 '22 00:09

Guy Sirton