Hi,
First, the user doesn't knows, what option they have and what
the advantages and disadvantages of the option is. The idea of best
practice is, to give him an over view. It is not a "must" it is a "can".
Best practice is to use cxxtools logging. Nothing else. One of the advantages of tntnet is, that people can use whatever library they want. They may use boost or poco or something else when they like.
Cxxtools logging follows a philosophy. Logging must be lightweight and
quick and easy to use.
The bundle with logging and serialization is - in my opinion - to
hard. This makes the work complicate, not easy and not quick.
To use cxxtools logging you must learn more than with POCO or
boost. You must learn using loggin class, serialization and
a markup language. You can't use logging class alone.

Configuring logging with serialization is a feature, which was added not so long ago. It is great for those, who are familiar with serialization. I can recommend to learn using serialization since it is not only good for logging but solves many problems.

For those, who just want to use cxxtools logging, the easy way is to add "log_init()" into the main function, log_define("somecategory") to each source file and use log_error, log_info or log_debug to output something. To enable logging, create a file "log.properties" with just one line "rootlogger=D" and you get all your debug output. So it is easy and quick.

That is all, people has to know to get started. Nothing about serialization and the complicated stuff. I feel, it is easier than anything else.

Runtime configuration is possible but a little more complicated. It is also possible but not that easy. I quickly wrote a example, how to realize it:

   #include <iostream>
   #include <cxxtools/log.h>
   #include <cxxtools/serializationinfo.h>
   #include <cxxtools/arg.h>

   int main(int argc, char* argv[])
   {
      try
      {
        cxxtools::SerializationInfo si;
        si.addMember("rootlogger") <<= "INFO";
        cxxtools::SerializationInfo& loggers = si.addMember("logger");
        while(true)
        {
          cxxtools::Arg<std::string> verbose(argc, argv, 'v');
          if (!verbose.isSet())
            break;
          loggers.addMember(verbose) <<= "DEBUG";
        }

        log_init(si);

        foo();
        bar();
      }
      catch (const std::exception& e)
      {
        std::cerr << e.what() << std::endl;
      }
   }

When building that into say "foo", you can call it with "./foo -v foo -v bar" to enable debug for categories "foo" and "bar". I know that it is not really intuitive to configure logging that way and not documented at all since it is not really the suggested way to do it but it is possible.

You have already saw, how to configure logging using json or xml. I find it useful, that I can use a single configuration file to configure my application including logging. Try that with poco or some other logging library and you will see, that it will get complicated quickly.

Make simple stuff simple and difficult stuff possible. That is the idea.

One option is to add a nicer API to configure cxxtools logging.


Tommi
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to