From: LECLERCQ N. <nic...@so...> - 2002-05-03 10:03:49
|
Hi there, After a preliminary discussion with Bastiaan, I suggest to had to = following features to log4cpp: 1 - AsyncAppender class.=20 The log4j doc says: <The AsyncAppender lets users log events = asynchronously. It uses a bounded buffer to store logging events. It = will collect the events sent to it and then dispatch them to all the = appenders that are attached to it. You can attach multiple appenders to = an AsyncAppender. The AsyncAppender uses a separate thread to serve the = events in its bounded buffer>. In order to write the AsyncAppender, we first need to implement an = AppenderAttachable class that could be shared between the Category class = and the AsyncAppender class (code factorization). All the existing code = dedicated to the Appenders management (i.e. such as addAppender, = removeAppender, ...) should be encapsulated in the AppenderAttachable = class. Then we need a log4cpp::threading::Thread class. That's not a big = problem but we have to choose an interface compatible with (potentially) = all underlying implementation of threads. Since the need is basic, only = the fundamental features are required and the Thread class interface = could be something like:=20 class Thread [: private myPreferredThreadingPackage::Thread ] { public : =09 // Define only 3 levels of priority. enum { THREAD_PRIORITY_LOW =3D 0, THREAD_PRIORITY_NORMAL,=09 THREAD_PRIORITY_HIGH,=09 } Priority; Thread (const char* name); Thread (const std::string& name); // Ctors virtual ~Thread(); // Dtors int start (void); // Start the thread. virtual void run (void) =3D 0; // Override this method to provide functionality to your thread. void join (long milli_secs =3D 0); // Wait at most milli_secs for this thread to terminate. If milli_secs = =3D=3D 0 then wait for ever. void setPriority (int new_prio); // Set the priority of this thread. int getPriority (void) const; =20 // Get the priority of this thread.=20 //... anything else? sleep, yield, ... }; =20 The last thing we need to implement the AsyncAppender class is something = similar to the log4j BoundedFIFO. The STL queue is perfectly adapted to = implement such a class. 2 - Log4Cpp class. The aim of the Log4Cpp class is to encapsulate the init/shutdown stuffs. = class Log4Cpp { public: static int init (void); // Initializer. Return -1 on error, 0 otherwise. static void shutdown (void); // Cleanup everything before quitting.=20 }; Some packages (such as Java Threads for C++) need to be initialized to = work properly. The Log4Cpp::init could be a good place for that. The = Category::shutdown call could also be moved to Log4Cpp::shutdown.=20 3 - Logger and Level classes Just to reflect log4j 1.2 changes. I'm looking forward to your reactions. Nicolas SOLEIL project - http://www.soleil.u-psud.fr. |