]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/log.h
API: Include tbf.h and trie.h
[libucw.git] / ucw / log.h
index d0f1a9f8192f166a346eccc82e43b539de6a4353..d4cc525df083a097c7a4a003031dace4327db60d 100644 (file)
--- a/ucw/log.h
+++ b/ucw/log.h
 #ifndef _UCW_LOG_H_
 #define _UCW_LOG_H_
 
-#include "ucw/clists.h"
+#include <ucw/clists.h>
+
+#ifdef CONFIG_UCW_CLEAN_ABI
+#define log_add_substream ucw_log_add_substream
+#define log_check_configured ucw_log_check_configured
+#define log_close_all ucw_log_close_all
+#define log_close_stream ucw_log_close_stream
+#define log_configured ucw_log_configured
+#define log_find_type ucw_log_find_type
+#define log_new_configured ucw_log_new_configured
+#define log_new_fd ucw_log_new_fd
+#define log_new_file ucw_log_new_file
+#define log_new_stream ucw_log_new_stream
+#define log_new_syslog ucw_log_new_syslog
+#define log_register_type ucw_log_register_type
+#define log_rm_substream ucw_log_rm_substream
+#define log_set_default_stream ucw_log_set_default_stream
+#define log_set_format ucw_log_set_format
+#define log_stream_by_flags ucw_log_stream_by_flags
+#define log_switch ucw_log_switch
+#define log_switch_disable ucw_log_switch_disable
+#define log_switch_enable ucw_log_switch_enable
+#define log_syslog_facility_exists ucw_log_syslog_facility_exists
+#define log_type_name ucw_log_type_name
+#endif
 
 /*** === Messages and streams ***/
 
@@ -22,6 +46,7 @@ struct log_msg {
   char *m;                             // The formatted message itself, ending with \n\0
   int m_len;                           // Length without the \0
   struct tm *tm;                       // Current time
+  struct timeval *tv;
   uns flags;                           // Category and other flags as passed to msg()
   char *raw_msg;                       // Unformatted parts
   char *stime;
@@ -43,6 +68,7 @@ struct log_stream {
   clist substreams;                    // Pass the message to these streams (simple_list of pointers)
   int (*handler)(struct log_stream *ls, struct log_msg *m);    // Called to commit the message, return 0 for success, errno on error
   void (*close)(struct log_stream* ls);        // Called upon log_close_stream()
+  void *user_data;                     // Not used by the logging system
   // Private data of the handler follow
 };
 
@@ -72,7 +98,7 @@ enum ls_flag {
 /***
  * === Message flags
  *
- * The @flags parameter of msg() is divided to several groups of bits (from the LSB):
+ * The @flags parameter of <<basics:msg()>> is divided to several groups of bits (from the LSB):
  * message severity level (`L_xxx`), destination stream, message type
  * and control bits (e.g., `L_SIGHANDLER`).
  ***/
@@ -110,6 +136,8 @@ enum ls_flagmasks {                 // Bit masks of groups
 #define LS_SET_TYPE(type)      ((type) << LS_TYPE_POS)                         /** Convert message type to flags **/
 #define LS_SET_CTRL(ctrl)      ((ctrl) << LS_CTRL_POS)                         /** Convert control bits to flags **/
 
+#define LS_NUM_TYPES (1 << LS_TYPE_BITS)
+
 /** Register a new message type and return the corresponding flag set (encoded by `LS_SET_TYPE`). **/
 int log_register_type(const char *name);
 
@@ -175,6 +203,17 @@ static inline struct log_stream *log_default_stream(void)
   return log_stream_by_flags(0);
 }
 
+/**
+ * Make the specified stream the default destination.
+ *
+ * In fact, it takes the fixed default stream and attaches @ls as its only
+ * substream. If there were any other substreams, they are removed.
+ *
+ * Log streams created by <<basics:log_file()>> or @log_configured() are made default
+ * by calling this function.
+ **/
+void log_set_default_stream(struct log_stream *ls);
+
 /**
  * Close all open streams, un-initialize the module, free all memory and
  * reset the logging mechanism to use stderr only.
@@ -188,8 +227,14 @@ void log_close_all(void);
  * even in multi-threaded programs.
  ***/
 
-struct log_stream *log_new_file(const char *path);             /** Create a stream bound to a log file. **/
-struct log_stream *log_new_fd(int fd);                         /** Create a stream bound to a file descriptor. **/
+struct log_stream *log_new_file(const char *path, uns flags);  /** Create a stream bound to a log file. See `FF_xxx` for @flags. **/
+struct log_stream *log_new_fd(int fd, uns flags);              /** Create a stream bound to a file descriptor. See `FF_xxx` for @flags. **/
+
+enum log_file_flag {           /** Flags used for file-based logging **/
+  FF_FORMAT_NAME = 1,          // Internal: Name contains strftime escapes
+  FF_CLOSE_FD = 2,             // Close the fd with the stream (use with log_new_fd())
+  FF_FD2_FOLLOWS = 4,          // Maintain stderr as a clone of this stream
+};
 
 /**
  * When a time-based name of the log file changes, the logger switches to a new