andrew-d / cpplog Goto Github PK
View Code? Open in Web Editor NEWSimple C++ logging library
License: MIT License
Simple C++ logging library
License: MIT License
hi, i believe ostrstream is deprecated. well at least i keep getting annoying warnings about it being deprecated. here's a quick update:
a fix: cpplog.h
9: -> #include
180: -> std::ostringstream stream;
304: -> char lastChar = m_logData->buffer[m_logData->stream.str().size() - 1];
cheers!
i can't seem to find anything like layout, format, etc. in the source code to determine what items one line of log output contains in what format. does cpplog simply not support that or do i look in the wrong corner ?
I encountered a couple of issues compiling with mingw (gcc 4.5.2). Here's a patch, keep up the good work!
diff ./cpplog.hpp c:\Users\ben\Downloads\andrew-d-cpplog-566832a/cpplog.hpp
126c126
< inline bool slocaltime(::tm* out, const ::time_t* in)
---
> bool slocaltime(::tm* out, const ::time_t* in)
128c128
< #if defined(_WIN32) && defined(_MSC_VER)
---
> #ifdef _WIN32
130,132d129
< #elif defined(__MINGW32__)
< out = localtime(in);
< return out!=NULL;
139c136
< inline bool sgmtime(::tm* out, const ::time_t* in)
---
> bool sgmtime(::tm* out, const ::time_t* in)
141c138
< #if defined(_WIN32) && defined(_MSC_VER)
---
> #ifdef _WIN32
143,145d139
< #elif defined(__MINGW32__)
< out = gmtime(in);
< return out!=NULL;
diff ./outputdebugstream.hpp c:\Users\ben\Downloads\andrew-d-cpplog-566832a/outputdebugstream.hpp
17c17
< inline void output_debug_string(const Elem* e);
---
> void output_debug_string(const Elem* e);
21c21
< inline void outputdebug_buf<char>::output_debug_string(const char* e)
---
> void outputdebug_buf<char>::output_debug_string(const char* e)
27c27
< inline void outputdebug_buf<wchar_t>::output_debug_string(const wchar_t* e)
---
> void outputdebug_buf<wchar_t>::output_debug_string(const wchar_t* e)
Hi,
I tried this library assuming that it was header-only as advertised and ran straight into compilation problems when trying the main.cpp.
I removed the THREADING and SYSTEM_IDS as well as the boost libs from the Makefile and now I can build and all the threads pass.
Is there some documentation as to what I am missing out if I use the library in this way?
Can I still use the library without boost-thread using, say OpenMPI? What kind of shortcomings do I need to expect?
Best,
Matthias
Hi,
I'm wondering what the easiest way is to log fatal and error level messages to file and to stderr. Other messages only to file.
So far, I've been using the FileRotationLogger, but it got me confused when error messages wouldn't show up on the screen anymore.
Is it a good idea to have a TeeLogger that combines the FileRotationLogger (that logs debug and up) with a stderrLogger (that logs error and up only)?
Or would it be better to directly alter the LogMessage method in some form?
Best,
Matthias
you can use this instead
http://blog.tomaka17.com/2011/07/redirecting-cerr-and-clog-to-outputdebugstring/
See error message below
main.cpp:190:2: error: pasting formed 'LOG_"LL_WARN"', an invalid preprocessing token
LOG_IF(LL_WARN, log, 1 == 2) << "This should not be logged"; TEST_EXPECTED("This should not be logged", LL_WARN, false);
^
./cpplog.hpp:763:105: note: expanded from:
#define LOG_IF(level, logger, condition) !(condition) ? (void)0 : cpplog::helpers::VoidStreamClass() & LOG(#level, logger)
^
./cpplog.hpp:758:32: note: expanded from:
#define LOG(level, logger) LOG_##level(logger)
Hi,
I (think I) found a missing header inclusion:
When I compiled with -D_DEBUG, I received the following error (first line by me to locate where in the #ifdefs I am)
cpplog.hpp:441:6: warning: #warning B [-Wcpp]
cpplog.hpp: In member function ‘void cpplog::LogMessage::Flush()’:
cpplog.hpp:442:6: error: ‘::exit’ has not been declared
I fixed this by adding
#include <cstdlib>
to cpplog.hpp.
and changing to
std::exit(1)
which may not have been necessary.
Did you just forget this (after all, it was compiled away in your tests) or am I missing something?
Best,
Matthias
C++11 implicitly makes destructors noexcept, causing the system to terminate() instead of throwing.
~LogMessage noexcept(false)
I just git-cloned cpplog and I'm trying to use it. This is straight from the shell:
host:cpplog user$ g++ -c -o main.o main.cpp
In file included from /usr/include/c++/4.2.1/backward/strstream:51,
from main.cpp:6:
/usr/include/c++/4.2.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
I believe this is the deprecation warning mentioned in the other bug report.
In file included from main.cpp:8:
cpplog.hpp: In member function ‘void cpplog::LogMessage::Init(const char*, unsigned int, cpplog::loglevel_t)’:
cpplog.hpp:295: error: ‘boost::interprocess::detail’ has not been declared
cpplog.hpp:296: error: ‘detail’ is not a member of ‘boost::interprocess’
cpplog.hpp:296: error: expected `;' before ‘::’ token
main.cpp: At global scope:
main.cpp:12: error: ‘detail’ is not a namespace-name
main.cpp:12: error: expected namespace-name before ‘;’ token
main.cpp: In function ‘void getLogHeader(std::string&, cpplog::loglevel_t, const char*, unsigned int)’:
main.cpp:24: error: ‘get_current_process_id’ was not declared in this scope
main.cpp:25: error: ‘get_current_thread_id’ was not declared in this scope
I haven't done a lot of C++ development recently, but I believe the required boost include file is boost/interprocess/detail/os_thread_functions.hpp
and it seems to me it is actually found (it is located at /usr/local/include/boost/interprocess/detail/os_thread_functions.hpp
on my system), so no idea what the problem is. Might be something simple. As a workaround, activate #define CPPLOG_NO_SYSTEM_IDS
in cpplog.hpp
, line 61.
main.cpp: In function ‘int TestCheckMacros()’:
main.cpp:261: warning: NULL used in arithmetic
main.cpp:265: warning: NULL used in arithmetic
(ignore that for now).
host:cpplog user$ g++ -o cpplog main.o
Undefined symbols for architecture x86_64:
"boost::thread::~thread()", referenced from:
boost::thread::operator=(boost::detail::thread_move_t<boost::thread>)in ccAUyipp.o
cpplog::BackgroundLogger::Init() in ccAUyipp.o
cpplog::BackgroundLogger::BackgroundLogger(cpplog::BaseLogger&)in ccAUyipp.o
cpplog::BackgroundLogger::~BackgroundLogger()in ccAUyipp.o
cpplog::BackgroundLogger::~BackgroundLogger()in ccAUyipp.o
"boost::detail::get_current_thread_data()", referenced from:
boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*, _opaque_pthread_cond_t*)in ccAUyipp.o
"boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in ccAUyipp.o
"boost::detail::thread_data_base::~thread_data_base()", referenced from:
boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, cpplog::BackgroundLogger>, boost::_bi::list1<boost::_bi::value<cpplog::BackgroundLogger*> > > >::~thread_data()in ccAUyipp.o
boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, cpplog::BackgroundLogger>, boost::_bi::list1<boost::_bi::value<cpplog::BackgroundLogger*> > > >::~thread_data()in ccAUyipp.o
"vtable for boost::detail::thread_data_base", referenced from:
boost::detail::thread_data_base::thread_data_base()in ccAUyipp.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"boost::thread::start_thread()", referenced from:
boost::thread::thread<void (cpplog::BackgroundLogger::*)(), cpplog::BackgroundLogger*>(void (cpplog::BackgroundLogger::*)(), cpplog::BackgroundLogger*)in ccAUyipp.o
"boost::thread::thread()", referenced from:
cpplog::BackgroundLogger::BackgroundLogger(cpplog::BaseLogger&)in ccAUyipp.o
"boost::thread::join()", referenced from:
cpplog::BackgroundLogger::~BackgroundLogger()in ccAUyipp.o
cpplog::BackgroundLogger::~BackgroundLogger()in ccAUyipp.o
"typeinfo for boost::detail::thread_data_base", referenced from:
typeinfo for boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, cpplog::BackgroundLogger>, boost::_bi::list1<boost::_bi::value<cpplog::BackgroundLogger*> > > >in ccAUyipp.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
One major advantage of using a self-proclaimed 'header only' log library is that I don't have to deal with issues around linking with other libraries. I don't need multi-threading at the moment, so activate #define CPPLOG_NO_THREADING
in cpplog.hpp
, line 62.
host:cpplog user$ ./cpplog
Testing logging macros... done!
Testing debug-logging macros... done!
Testing conditional macros... done!
Testing conditional macros... done!
Testing TeeLogger... done!
Testing auto-rotating loggers... (waiting) done!
Testing other logging macros... done!
------------------------------
All tests passed!
Conclusion: The two defines could be activate by default to reduce dependencies and make it easier for people to get started on cpplog.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.