The purpose of this project is to port the excellent Log for Java (log4j) logging library to C++.
See all
Members (154)
log4cplus's profile photo
Peace Da's profile photo
Martin Runge's profile photo
Yelli Cazalon's profile photo
Gabriel Bota's profile photo
Linus Lirpa (Tobias W.)'s profile photo
Musten Jiruwala's profile photo
Ryan Thompson's profile photo
Manikandan Thirugnanam's profile photo
Andreas Roth's profile photo
christopher dawes's profile photo
Kyle Leber's profile photo
Rochmat Mustopa's profile photo
DrDoom77's profile photo
Géry Vessère's profile photo
Lior Amar's profile photo
Emma Robert's profile photo
Myeongho AN's profile photo
abdul samad's profile photo
Jim Hague's profile photo
Cen Rao's profile photo
Subhamoy Sengupta's profile photo
Umesh Sharma's profile photo
Yin laiyier's profile photo

Stream

Join this community to post or comment
 
Hi,

I have a really strange error using log4cplus.
My process exits with code 11. If I run it in the debugger, there is a "SIGSEGV: invalid address".
Here is the call stack:
pthread_join
log4cplus::thread::AbstractThread::join()
log4cplus::AsyncAppender::close()
log4cplus::spi::LoggerImpl::closeNestedAppenders()
log4cplus::Hierarchy::shutdown()
log4cplus::Hierarchy::~Hierarchy()

I have tried to simplify the code and here is what I have:
#include <iostream>
#include <log4cplus/logger.h>
#include <log4cplus/configurator.h>
int main()
{
log4cplus::PropertyConfigurator config("/tmp/log.txt");
config.configure();

return 0;
}

And the config file:
log4cplus.rootLogger=OFF, A1
log4cplus.logger.L1=OFF, A5
log4cplus.logger.L2=OFF, A2
log4cplus.logger.L4=OFF, A3
log4cplus.logger.L6=OFF, A4
log4cplus.logger.L7=OFF, A1

log4cplus.appender.A1=log4cplus::AsyncAppender
log4cplus.appender.A1.Appender=log4cplus::ConsoleAppender

log4cplus.appender.A2=log4cplus::AsyncAppender
log4cplus.appender.A2.Appender=log4cplus::ConsoleAppender

log4cplus.appender.A3=log4cplus::AsyncAppender
log4cplus.appender.A3.Appender=log4cplus::ConsoleAppender

log4cplus.appender.A4=log4cplus::AsyncAppender
log4cplus.appender.A4.Appender=log4cplus::ConsoleAppender

log4cplus.appender.A5=log4cplus::AsyncAppender
log4cplus.appender.A5.Appender=log4cplus::ConsoleAppender

If I change the logger name L7 to L6, I don't have an error anymore.
Actually, if I delete any configuration line, I don't have an error anymore but I noticed that the name of my logger L7 worried.

I use log4cplus 1.1.3-0.4.rc3.
Actually, I use it with centos7 and a newer version of log4cplus is not available with yum.

I have a workaround for my problem, putting an "A" before the logger name which has a problem so it's not blocking but I don't know when it will happen again because I don't understand why the name is a problem.

If this problem is fixed in a newer version, I can manualy upgrade the library.

Thanks in advance.

1
Sergei Nikulov's profile photoFabian Jacquet's profile photo
2 comments
 
Ok, done. #195
Add a comment...

log4cplus
owner

Diskuse  - 
 
 
I have release log4cplus 1.1.3-RC7. It is a bugs fixing release:

- Fixed SF#322. -- C++11 construct that should not be present.

- Fixed FreeAddrInfoA and FreeAddrInfoW not found. -- This required bump to minimal version to Windows XP SP2.

- Fixed missing thread's alternative name. -- GitHub bug #137.

- Fixed GitHub bug #155. -- Process shutdown issues.

- Fixed GitHub bug #136. -- Adjust weekly, daily and twice daily rollover time for DailyRollingFileAppender by time zone offset so that the rollover happens at midnight, etc., of local time instead of UTC time.

- Fixed CMake/Visual Studio 2010 compilation. -- GitHub issue #188.
1
1
Add a comment...
 
I've been using log4cplus-1.2.0-rc3 in my application for some time; it works great linked dynamically. But, for portability reasons, I find that I must switch all libraries to being statically linked. I have done this easily by using BUILD_SHARED_LIBS=false, linking against log4cplusS, and adding '# define LOG4CPLUS_STATIC' to the appropriate header. However, I now find that linking fails specifically on log4cplus: 'undefined reference to log4cplus::BasicConfigurator'...etc. Any idea why?
1
Stuart Bowman's profile photo
 
Never mind. I appear to have solved it. A lower-level library was also linking against log4cplus, but still doing it dynamically. Once I fixed that, everything built again and my test pass. Thanks!
Add a comment...

log4cplus
owner

Diskuse  - 
 
 
I have released log4cplus 1.2.0. The changes from the last release candidate are minimal:

- Fixed SourceForge bug #324, MinGW compilation issue. Use InterlockedExchangeAdd instead of InterlockedAdd. The former is supported by older MinGW.

- Fixed GitHub bug #137. Fix missing thread's alternative name.
1
Add a comment...
 
Hi,

do log4cplus::PatternLayout has some way to output date-time in ISO 8601 full format, in UTC time + TZD (Time Zone Designator)?
I.e. 1994-11-05T08:15:30+01:00

As an alternative, does PatternLayout support the %z (lowercase), supported by strftime since C99?
1
Václav Haisman's profile photoRoal Zanazzi's profile photo
2 comments
 
Ok, I found the problem.
I was using the log4cplus (oldish 1.1.2-rc2) compiled by a co-worker with Microsoft Visual Studio 2013 that seems to not correctly support strftime the %z formatter option (outputs the TZ name instead of TZD).

I rebuilt the library with Visual Studio 2015 and now %z correctly outputs "+100" in my case.

Thanks for your time.
Add a comment...
 
Hello there,

 I've an issue with an  application using log4cplus that, sincerely, gets me puzzled. The application is multithread, having 2 threads for two log4cplus appenders: A time & size rolling appender used for the main log, and a custom appender for access log (this is a HTTP based server).

 This application runs in many different customers and testing servers, from bare metal servers to VMs, and now even container'd docker environment. No problem at all, but in one customer; in this one, the logging gets blocked, and nothing else is written until the application is restarted.

 No specific behavior, no rules and no pattern: it just happens, sometimes more in one of the nodes, sometimes does not happen for weeks, and then happens in several nodes the same time.

 This customer is running the app in many VMs under ESXi with the VM images stored (and reading / writing) in a HP SAN. The only thing writing to disk is the log itself, no other application is running, and the kernel and system logs does not show this problem. There are two datacenters, with two similar SANs and two ESX clusters, and this is happening on both DCs.

 Debugging on this machine is difficult,  I'm setting up the environment with the customer, but preliminary tests have shown that the logging threads are blocked in a waitpid() call.

As said, this is running in dozens of other customers, with similar environments (but the SAN) and it's running just fine, no problems. Logs from ESXi / VCenter and the SAN monitoring do not show anything clear, there are no errors or nothing suspicious there.

 Any suggestion here would be really welcome, this has been happening for a while and nothing of the different things I've been testing seem to bring more information or anything clear about the issue?

 Thanks!
1
Alberto Curro's profile photoVáclav Haisman's profile photo
6 comments
 
+Alberto Curro Please do keep me posted. Is this happening during some special time like startup or shutdown? If you have some call stacks, you can send them to my email vhaisman@gmail.com, to keep them private. 
Add a comment...
 
Documentation of log4cplus is very weak. However there some examples in order to shallowly use it but I couldn't find any deep information about the library. For instance, "spi" namespace and classes in this namespace are very blurry. One can understand it by investigating the code but it takes more time. Do you know any detailed tutorial or document for log4cplus ?
2
1
Add a comment...

Ashwin D

Diskuse  - 
 
Is it possible to create Log4cplus as s static library... While configuring, i mentioned --enable-static.. But its not creating .a file, rather again creating so files. Is any other way to create as a static library. 
1
Ashwin D's profile photoVáclav Haisman's profile photo
3 comments
 
+Ashwin D That might be the problem. Can you post config.log for somewhere for inspection or send it to my email vhaisman@gmail.com, if you want to keep it private.
Add a comment...
 
Hi,

why do i need the log4cplus.dll in my folders?
Can i compile the Sourcecode that i doesn't need the dll?
1
Tobias Dornheim's profile photoVáclav Haisman's profile photo
3 comments
 
Your code needs to define LOG4CPLUS_STATIC preprocessor symbol. Do not forget to set up includes and libraries paths and/or add log4cplusS to your projects References.
Add a comment...

log4cplus
owner

Diskuse  - 
 
 
log4cplus 1.1.3-RC4 released

- Allow negative maximal length in pattern specifier to make trimming of end instead of beginning possible. E.g., allow %.-1p to get initial letters of log level.

- Visual Studio DLL builds now have a resource with basic information about the library. (Oskari Timperi)

- LOG4CPLUS_*_FMT() macros can now be invoked with just formatting string, without additional arguments. (Zhang Shengfa)

- Added setCurrentThreadName() and setCurrentThreadName2() to allow setting current thread name to custom string instead of the default stringified thread ID. (Zhang Shengfa)
1
Add a comment...

Created by

About this community

log4cplus is a simple to use C++ logging API providing thread-safe, flexible, and arbitrarily granular control over log management and configuration. It is modelled after the Java log4j API.
 
Hi all,

I would like to add a log message to every appender configured on start up of my process.
I need this to know if the process has restarted simply reading any log file.

I could get all appenders in each existing logger to call doAppend but i'm not sure it's the best solution.

Is it possible to get every appender without using loggers? Or should I have this information otherwise?

Thank you.


1
Václav Haisman's profile photoFabian Jacquet's profile photo
2 comments
 
Thanks a lot
Add a comment...

Lior Amar

Diskuse  - 
 
Hi,
First apologies if this is not the right place
I have a multithreaded app where I need to send the output of each thread to a separate log file (rotating one). I would like to use the properties file to configure the appender (file rotatating) and to create the loggers (one for each thread) programatically from the code.

Can I access the appender created in the properties file in my C++ code to attache it to a logger I just created?

Thanks.
1
Václav Haisman's profile photo
 
Appenders are only created for loggers and attached to the loggers. If an Appender is not attached to a logger by the time PropertyConfigurator is done configuring then such Appender is destroyed (its reference count goes to zero). So it is not possible to do this directly.

Indirectly, you could attach all of your Appenders in your configuration properties file to a single dummy Logger or even root Logger and then ask for all Appenders by calling `getAllAppenders` on your dummy/root logger. Then you can ask Appender for its name by using `getName` and reassign the Appender to your target Logger. After you are done reassigning Loggers, clear all Loggers from your dummy/root Logger by calling `removeAllAppenders`.

This might work. :)
Add a comment...

Io Carmine

Diskuse  - 
 
Hi, is there a way to have the PID as part of the filename in the configration of a FileAppender. I have more processes and I would like them to share the same config file but to have each of them writing in its own log file. Is this possible to achieve with log4cplus?

something like: 

log4cplus.appender.LOG=log4cplus::FileAppender
log4cplus.appender.LOG.File=c:\temp\trace_p-%-5.5p.log
1
Václav Haisman's profile photo
 
No, there is no way to do that directly. You could get a similar effect by defining some environment variable and using it in the file name like ${FOO}.
Add a comment...

log4cplus
owner

Diskuse  - 
 
I have released log4cplus 1.2.0-RC6:

- Fixed Visual Studio build issue #322 related to WinSock functions being used and second about C++11 syntax. This forces minimum version of Windows supported by this release to Windows XP SP2.

- Added DatePattern property to DailyRollingFileAppender configuration -- This property specifies filename suffix pattern to use for periodical backups of the logfile. (Alexey Morozov)

- Added RollOnClose property to DailyRollingFileAppender and TimeBasedRollingFileAppender configuration -- This property specifies whether to rollover log files upon shutdown. By default it's set to true to retain compatibility with legacy code. (Alexey Morozov)

- Normalized line endings, used .gitattributes to enforce it.

https://sourceforge.net/p/log4cplus/news/2016/01/log4cplus-120-rc6-released/
1
2
Add a comment...
 
i have this below configuration, but when file created. that file was empty. can any body help me?

log4cplus.rootLogger=DEBUG, STDOUT
log4cplus.logger.testlogger=TRACE, TEST
log4cplus.additivity.testlogger=FALSE

log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
log4cplus.appender.STDOUT.layout.ConversionPattern=%D{%m/%d/%y %H:%M:%S }  %n
log4cplus.appender.TEST=log4cplus::TimeBasedRollingFileAppender
log4cplus.appender.TEST.Schedule = DAILY
log4cplus.appender.TEST.FilenamePattern=%d_biller.log
log4cplus.appender.TEST.layout=log4cplus::PatternLayout
log4cplus.appender.TEST.layout.ConversionPattern=%D{%Y-%m-%d %H:%M:%S} %-5p %c <%x> - %m%n
1
Václav Haisman's profile photo
 
Try to run your test with environment variable `LOG4CPLUS_LOGLOG_DEBUGENABLED` set to 1. It will print out some information about file rollovers during run time.
Add a comment...
 
Hi!

I'm trying to compile the downloaded source (master) on my debian (jessie, 64bit) system and I always got the following error when I make it:

src/global-init.cxx:35:24: fatal error: ThreadPool.h: No such file or directory
  #include "ThreadPool.h"
                        ^
compilation terminated.
Makefile:2113: recipe for target 'src/liblog4cplus_la-global-init.lo' failed
make[2]: * [src/liblog4cplus_la-global-init.lo] Error 1
make[2]: Leaving directory '/root/log4cplus-master'
Makefile:2617: recipe for target 'all-recursive' failed
make[1]: * [all-recursive] Error 1
make[1]: Leaving directory '/root/log4cplus-master'
Makefile:1450: recipe for target 'all' failed
make: * [all] Error 2

Some lib is missing from my system?
What should I do ?

Thanks!
1
Václav Haisman's profile photoCsaba Bordás's profile photo
2 comments
 
Thanks for your answer!
Helped a lot!
I figured it out! Now it works fine!
Add a comment...

Ashwin D

Diskuse  - 
 
i had generated liblog4cplus.a static library, i tried using the same with necessary libs in my project. It throws log4cplusinitialize referenced symbol not found... And while creating a my .so along with static log4cplus.a lib, i got a ld:warning like " loblog4cplus.configurator" wrong ELFCLASS 32..Do i need to create 64 bit lib, if any suggestions how to do it.... if not what mite be the above error(referenced symbol not found) due to?  any idea.. 
1
Václav Haisman's profile photoAshwin D's profile photo
2 comments
 
Nothing!!. Actuallt i had configured the download wirh the following: " Configure --enable-static. And i done "make" and  i got the liblog4cplus.a file, which i want to use in my project as a static link library. While doing that i got ELFCLASS32 warning, so i wanted to make the library as compatible for 64 bit.. i am sorry if i confused you. Any idea on that..Or do u require myy config files....
Add a comment...

Ashwin D

Diskuse  - 
 
Hi , I want to use log4cplus for a c++ project in solaris. What do i need to do first? 
1
Václav Haisman's profile photoAshwin D's profile photo
7 comments
 
+Václav Haisman sure...
Add a comment...
 
Is there an Ubuntu repository, from where I can get the latest and greatest of this? The version in the Trusty Canonical repos is too old.
1
Václav Haisman's profile photo
 
As far as I know, there is not any. 
Add a comment...

log4cplus
owner

Diskuse  - 
 
 
*log4cplus 1.2.0-RC3 released*

- Fixed various issues related to unspecified behaviors which manifested when log4cplus was compiled using Clang.
SysLogAppender now recognize SyslogHost property as synonym for host property.

- Improved compatibility of TTCCLayout with log4j's. Added ThreadPrinting, CategoryPrefixing and ContextPrinting configuration properties.

- Allow negative maximal length in pattern specifier to make trimming of end instead of beginning possible. E.g., allow %.-1p to get initial letters of log level.

- New appender TimeBasedRollingFileAppender. (Alexander Malinin)
LOG4CPLUS_*_FMT() macros can now be invoked with just formatting string, without additional arguments. (Zhang Shengfa)

- Insert to/from string/log level conversion functions to the beginning of vector to favour user defined log levels and conversion functions.
1
Add a comment...