C++ logger and XML parser

C++ logger and XML parser

Postby Knitter » 31 May 2012, 15:52

Hi,

Since most of the games here are either C or C++, does anyone know of a good logger library or logging solution that would be small, have the ability to be turned on/off for debug/release, outputs to a stream and is free? I've looked around but most libraries seem too big for what I want.

My goal is to be able to replace all the print statements (std::cout << "something happend") for some that I can just strip when I want to have a release binary.

One other piece of code I need is a parsing library, XML is probably going to be what I'm going to use (any better suggestions?). I'm writing some code in my version of Linwarrior3D and I wanted to try adding some mission support to the game.
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: C++ logger and XML parser

Postby odamite » 31 May 2012, 16:13

Hi, I don't have much experience with loggers but here's some suggestions from reddit/r/cpp. However I like to use simpler (and maybe faster) libraries and here's what I found: C++ Trivial Logger which consist only 1 source files and 2 header.

About the XML parser. Of course there's the libxml. But once again there is something much simpler: tinyxml2. It's just just 1 header and source file.
User avatar
odamite
 
Posts: 166
Joined: 16 Jan 2012, 16:28

Re: C++ logger and XML parser

Postby Knitter » 31 May 2012, 16:27

Thanks for the reply. I'm looking at tinyxml2 and it looks to be what I want, thought I'm still deciding if simple XML definitions is enough or if I should try Lua.

Somehow I missed that Trivial Logger lib in the searches I made...
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: C++ logger and XML parser

Postby sireus » 31 May 2012, 17:41

Knitter {l Wrote}:XML is probably going to be what I'm going to use (any better suggestions?).

I'd recommend JSON over XML any day. That's mostly personal preference though (I find XML inconvenient to read and write).
sireus
 
Posts: 109
Joined: 24 May 2011, 20:10

Re: C++ logger and XML parser

Postby hc » 01 Jun 2012, 06:24

May not help you now (or soon) but for your interest: My intention was to add/write something simple along the lines of log4j for debugging/logging and for integration into the in-game-console.
github.com/hackcraft-de
hackcraft.de
User avatar
hc
LW3D Moderator
 
Posts: 213
Joined: 07 Feb 2011, 10:00
Location: far away

Re: C++ logger and XML parser

Postby Knitter » 01 Jun 2012, 10:51

hc {l Wrote}:May not help you now (or soon) but for your interest: My intention was to add/write something simple along the lines of log4j for debugging/logging and for integration into the in-game-console.

That would be nice to have :)
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: C++ logger and XML parser

Postby Zlodo » 01 Jun 2012, 16:00

There is also RapidXML, which claims to be much faster than tinyxml, I think mostly because in a nutshell goes out of its way to avoid copying strings but instead points to them in the original buffer containing the xml source (but it still expose a dom interface)

http://rapidxml.sourceforge.net/

I however second sireus, json is in my opinion much better than xml.
Zlodo
 
Posts: 17
Joined: 14 Dec 2009, 12:36

Re: C++ logger and XML parser

Postby maikesg78 » 07 Jun 2012, 14:32

apparently tinyxml2 is a lot faster anyway, personaly I would look at something like Xerces.
maikesg78
 
Posts: 3
Joined: 07 Jun 2012, 14:25

Re: C++ logger and XML parser

Postby mongrol » 15 Jun 2012, 11:49

I've just replaced all my std::cout logs with the awesome Blah library https://bitbucket.org/edd/blah/
mongrol
 
Posts: 4
Joined: 21 Jan 2012, 02:14

Re: C++ logger and XML parser

Postby Zlodo » 19 Jun 2012, 10:40

blah seems pretty nice!
Guess it's time I stop being lazy and throwing std::couts around and then commenting them out.
Zlodo
 
Posts: 17
Joined: 14 Dec 2009, 12:36

Re: C++ logger and XML parser

Postby Knitter » 20 Jun 2012, 09:59

I'm convinced by that logger, it was quite simple to configure and I like the way it works, thanks for the suggestion.
Knitter
 
Posts: 237
Joined: 03 Jul 2011, 22:52
Location: Portugal

Re: C++ logger and XML parser

Postby maikesg78 » 26 Jun 2012, 09:04

tinyxml2 or liquid xml c++ would meet your needs perfectly for the parsing. As for the logging library, look at Googles open source tool, http://code.google.com/p/google-glog/
maikesg78
 
Posts: 3
Joined: 07 Jun 2012, 14:25

Re: C++ logger and XML parser

Postby dusted » 18 Jul 2012, 10:51

I would take a look at SDL_Console it also has the ability to hook variables into the console which can be useful for debugging.

I discovered that after doing my own full implementation of a console with variable and function hooks, several print formats and interactive and stored scripting.. But I enjoy writing that kind of stuff.

If you want it REALLY simple, and very fast, I'd do few defines, the call looks like a C call, but it is using streams all the way through, and no code is generated if the debug parameter is not defined, enjoy.

{l Code}: {l Select All Code}
#include <iostream>

//include <log.hpp>
/* log.hpp start */

#ifdef debug_on
  #define logdebug(...) { cout << "[" <<__FILE__ <<":" << __LINE__ << "]: " << __VA_ARGS__ << endl; }
#else
  #define logdebug(...)
#endif

/* log.hpp end */

using namespace std;

int main()
{
  logdebug( "Hello World " << 123 );
  return(0);
}


Output:
Nothing.

With #define debug_on
[test.cpp:21]: Hello World 123
User avatar
dusted
 
Posts: 83
Joined: 27 Feb 2010, 04:35

Who is online

Users browsing this forum: No registered users and 1 guest