Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcutil / silclog.h
index 624120356e8dbd9a35752e7559832ac19d199aa6..af8358501e4d3bc849d6900ef031f02492b85546 100644 (file)
@@ -2,14 +2,13 @@
 
   silclog.h
 
-  Author: Giovanni Giacobbi <giovanni@giacobbi.net>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
   Copyright (C) 1997 - 2005 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
+  the Free Software Foundation; version 2 of the License.
 
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *
  * DESCRIPTION
  *
- *    This is the main logging channel id. There are currently four known
- *    logging channels (plus the debugging output channel), and they are
- *    ordered by importance.
- *
- *    See the source code for SILC coding conventions about how to choose
- *    the right output channel.
+ *    The log type.  This can be given to various silc_log_* routines.
  *
  * SOURCE
  */
 typedef enum {
-  /* Generic info channel file */
-  SILC_LOG_INFO,
-
-  /* This should be used for warnings and non critical failures */
-  SILC_LOG_WARNING,
-
-  /* Generic error and critical failure messages */
-  SILC_LOG_ERROR,
-
-  /* Fatal messages (usually situations that will lead to a program crash */
-  SILC_LOG_FATAL,
-
-  /* Total number logging channels */
-  SILC_LOG_MAX
+  SILC_LOG_INFO       = 1,     /* Generic info */
+  SILC_LOG_WARNING    = 2,      /* Warnings and non-critical failures */
+  SILC_LOG_ERROR      = 3,      /* Generic error and critical failure */
+  SILC_LOG_FATAL      = 4,     /* Fatal error */
 } SilcLogType;
 /***/
 
+#include "silclog_i.h"
+
 /****f* silcutil/SilcLogAPI/SilcLogCb
  *
  * SYNOPSIS
@@ -77,6 +63,7 @@ typedef enum {
  *    The logging custom callback function.  The `type' is the channel ID
  *    that triggered the event, which allows you to use the same callback
  *    function for multiple logging channels.
+ *
  *    The `message' parameter points to a null-terminated buffer containing
  *    the received message, while `context' is the caller-specified context.
  *    The message must not be modified or freed by the callback function.
@@ -101,6 +88,7 @@ typedef bool (*SilcLogCb)(SilcLogType type, char *message, void *context);
  *    corresponding offsets in the source files.  `message' points to a
  *    null-terminated buffer containing the debugging message, and `context'
  *    is the caller-specified context.
+ *
  *    The message must not be modified or freed by the callback function.
  *    If the function returns TRUE, SilcLog will assume the message as handled
  *    and won't run its default handler.
@@ -117,7 +105,8 @@ typedef bool (*SilcLogDebugCb)(char *file, char *function, int line,
  * SYNOPSIS
  *
  *    typedef bool (*SilcDebugHexdumpCb)(char *file, char *function, int line,
- *                                       unsigned char *data, SilcUInt32 data_len,
+ *                                       unsigned char *data,
+ *                                       SilcUInt32 data_len,
  *                                       char *message, void *context;
  *
  * DESCRIPTION
@@ -127,6 +116,7 @@ typedef bool (*SilcLogDebugCb)(char *file, char *function, int line,
  *    like it to be.  `file', `function', and `line' are the corresponding
  *    offsets in the source files.  `data' is the begin of the buffer that
  *    should be hexdumped, which is `data_len' bytes long.
+ *
  *    The `message' parameter points to a null-terminated buffer containing
  *    the received message, while `context' is the caller-specified context.
  *    The message must not be modified or freed by the callback function.
@@ -141,135 +131,8 @@ typedef bool (*SilcLogHexdumpCb)(char *file, char *function, int line,
                                 unsigned char *data, SilcUInt32 data_len,
                                 char *message, void *context);
 
-/* Global Variables */
-
-/****v* silcutil/SilcLogAPI/silc_log_timestamp
- *
- * NAME
- *
- *    bool silc_log_timestamp -- enable/disable fast logging timestamp
- *
- * DESCRIPTION
- *
- *    Causes SilcLog to add a timestamp as returned by silc_get_time().
- *    This may be useful for example if you run your application under a
- *    daemon helper like watchdog that adds its own timestamp.  Defaults to
- *    true.
- *
- ***/
-extern DLLAPI bool silc_log_timestamp;
-
-/****v* silcutil/SilcLogAPI/silc_log_quick
- *
- * NAME
- *
- *    bool silc_log_quick -- enable/disable fast logging output
- *
- * DESCRIPTION
- *
- *    SilcLog makes use of libc stream buffering output, which means that it
- *    saves HD activity by buffering the logging messages and writing them
- *    all together every some minutes (default is 5 minutes).
- *    Setting this variable to TRUE will force SilcLog to write messages to the
- *    filesystem as soon as they are received. This increases the CPU activity
- *    notably on bigger servers, but reduces memory usage.
- *    If you want to change the logging style on-the-fly, make sure to call
- *    silc_log_flush_all() after setting this variable to TRUE.
- *
- ***/
-extern DLLAPI bool silc_log_quick;
-
-/****v* silcutil/SilcLogAPI/silc_log_flushdelay
- *
- * NAME
- *
- *    long silc_log_flushdelay -- flushing time delay
- *
- * DESCRIPTION
- *
- *    Sets the logfiles flushing delay in seconds.  As for now, changing this
- *    value AFTER logfiles initialization won't take effect until previous
- *    delay time will expire; for example if you change from 300 seconds to
- *    60 seconds you will have to wait up to 300 seconds for this change to
- *    take effect.
- *    This value must be greater than 2 seconds.
- *
- ***/
-extern DLLAPI long silc_log_flushdelay;
-
-/****v* silcutil/SilcLogAPI/silc_debug
- *
- * NAME
- *
- *    bool silc_debug -- enable/disable debugging output
- *
- * DESCRIPTION
- *
- *    If silc_debug is set to FALSE, debugging functions won't procude any
- *    output.  This is useful when for example you compile in the debugging
- *    support but at a certain point you want to send the program in the
- *    background.
- *
- * SEE ALSO
- *    SILC_LOG_DEBUG
- *
- ***/
-extern DLLAPI bool silc_debug;
-
-/****v* silcutil/SilcLogAPI/silc_debug_hexdump
- *
- * NAME
- *
- *    bool silc_debug_hexdump -- enable/disable debugging output
- *
- * DESCRIPTION
- *
- *    If silc_debug_hexdump is set to FALSE, debugging functions won't produce
- *    any output.  This is useful when for example you compile in the debugging
- *    support but at a certain point you want to send the program in the
- *    background.
- *
- * SEE ALSO
- *    SILC_LOG_HEXDUMP
- *
- ***/
-extern DLLAPI bool silc_debug_hexdump;
-
 /* Macros */
 
-#if defined(WIN32)
-#ifndef __FUNCTION__
-#define __FUNCTION__ ""
-#endif
-#endif
-
-/****d* silcutil/SilcLogAPI/SILC_ENABLE_DEBUG
- *
- * NAME
- *
- *    #define SILC_ENABLE_DEBUG
- *
- * DESCRIPTION
- *
- *    Use this macro to enable the debugging in your application.  If
- *    SILC was compiled with debugging enabled, this macro enables it.
- *    Use this macro in your application's main header, or in place where
- *    you need to enable the debugging.
- *
- * NOTES
- *
- *    You still can control the debugging with silc_debug variable, on
- *    whether to actually print the debugging or not.  This macro is
- *    used to enable debugging, not to say it is printed or not.
- *
- * SOURCE
- */
-#define SILC_ENABLE_DEBUG      \
-  #ifndef SILC_DEBUG           \
-  #define SILC_DEBUG 1         \
-  #endif
-/***/
-
 /****d* silcutil/SilcLogAPI/SILC_LOG_INFO
  *
  * NAME
@@ -364,19 +227,19 @@ extern DLLAPI bool silc_debug_hexdump;
  *    This is a special wrapper to the debugging output (usually stderr).
  *    The standard behaviour is the same as SILC_LOG_INFO, with the difference
  *    that this macro also depends on the global define SILC_DEBUG.
+ *
  *    Undefining SILC_DEBUG causes these functions to be defined to an empty
  *    value, thus removing all debug logging calls from the compiled
  *    application.
- *    This macro is also affected by the global variable silc_debug.
  *
  * SOURCE
  */
 #if defined(SILC_DEBUG)
-#define SILC_LOG_DEBUG(fmt) silc_log_output_debug(__FILE__, \
-                               __FUNCTION__, \
-                               __LINE__, \
+#define SILC_LOG_DEBUG(fmt) silc_log_output_debug(__FILE__,    \
+                               __FUNCTION__,                   \
+                               __LINE__,                       \
                                silc_format fmt)
-#define SILC_NOT_IMPLEMENTED(string) \
+#define SILC_NOT_IMPLEMENTED(string)                                   \
   SILC_LOG_INFO(("*********** %s: NOT IMPLEMENTED YET", string));
 #else
 #define SILC_LOG_DEBUG(fmt) do { } while(0)
@@ -424,30 +287,29 @@ extern DLLAPI bool silc_debug_hexdump;
 
 /* Prototypes */
 
-/****f* silcutil/SilcLogAPI/silc_log_output
+/****f* silcutil/SilcLogAPI/silc_log_set_file
  *
  * SYNOPSIS
  *
- *    void silc_log_output(SilcLogType type, char *string);
+ *    bool silc_log_set_file(SilcLogType type, char *filename,
+ *                           SilcUInt32 maxsize,
+ *                           SilcSchedule scheduler);
  *
  * DESCRIPTION
  *
- *    This is the main function for logging output. Please note that you
- *    should rather use one of the logging wrapper macros.
- *
- *    If you really want to use this function, its usage is quite simple.
- *    The `type' parameter identifies the channel to use, while the `string'
- *    parameter must be a dynamic allocated (null-terminated) buffer, because
- *    it will be freed at the end of this function, for internal reasons.
- *    If there are registered callbacks for the specified type, this function
- *    will first trigger those callbacks.  The callback functions must NOT
- *    free or modify the original buffer.
+ *    Sets `filename', which can be maximum `maxsize' bytes long, as the new
+ *    logging file for the channel `type'.  If you specify an illegal filename
+ *    a warning message is printed and FALSE is returned.  In this case
+ *    logging settings are not changed.
  *
- * SEE ALSO
- *    SILC_LOG_INFO, SILC_LOG_WARNING, SILC_LOG_ERROR, SILC_LOG_FATAL
+ *    You can disable logging for a channel by specifying NULL filename, the
+ *    maxsize in this case is not important.  The `scheduler' parameter is
+ *    needed by the internal logging to allow buffered output and thus to
+ *    save HD activity.
  *
  ***/
-void silc_log_output(SilcLogType type, char *string);
+bool silc_log_set_file(SilcLogType type, char *filename, SilcUInt32 maxsize,
+                      SilcSchedule scheduler);
 
 /****f* silcutil/SilcLogAPI/silc_log_get_file
  *
@@ -468,30 +330,6 @@ void silc_log_output(SilcLogType type, char *string);
  ***/
 char *silc_log_get_file(SilcLogType type);
 
-/****f* silcutil/SilcLogAPI/silc_log_set_file
- *
- * SYNOPSIS
- *
- *    bool silc_log_set_file(SilcLogType type, char *filename,
- *                           SilcUInt32 maxsize,
- *                           SilcSchedule scheduler);
- *
- * DESCRIPTION
- *
- *    Sets `filename', which can be maximum `maxsize' bytes long, as the new
- *    logging file for the channel `type'.  If you specify an illegal filename
- *    a warning message is printed and FALSE is returned.  In this case
- *    logging settings are not changed.
- *
- *    You can disable logging for a channel by specifying NULL filename, the
- *    maxsize in this case is not important.  The `scheduler' parameter is
- *    needed by the internal logging to allow buffered output and thus to
- *    save HD activity.
- *
- ***/
-bool silc_log_set_file(SilcLogType type, char *filename, SilcUInt32 maxsize,
-                      SilcSchedule scheduler);
-
 /****f* silcutil/SilcLogAPI/silc_log_set_callback
  *
  * SYNOPSIS
@@ -530,7 +368,7 @@ void silc_log_set_callback(SilcLogType type, SilcLogCb cb, void *context);
  *    rather need to call silc_log_set_debug_callbacks() with NULL callbacks.
  *
  ***/
-void silc_log_reset_callbacks();
+void silc_log_reset_callbacks(void);
 
 /****f* silcutil/SilcLogAPI/silc_log_flush_all
  *
@@ -547,7 +385,7 @@ void silc_log_reset_callbacks();
  *    silc_log_quick
  *
  ***/
-void silc_log_flush_all();
+void silc_log_flush_all(void);
 
 /****f* silcutil/SilcLogAPI/silc_log_reset_all
  *
@@ -559,52 +397,12 @@ void silc_log_flush_all();
  *
  *    Forces all logging channels to close and reopen their streams.  Useful
  *    for example after a SIGHUP signal.
+ *
  *    Please note that this function could generate some warning messages if
  *    one or more logging channels point to an illegal filename.
  *
  ***/
-void silc_log_reset_all();
-
-/****f* silcutil/SilcLogAPI/silc_log_output_debug
- *
- * SYNOPSIS
- *
- *    void silc_log_output_debug(char *file, const char *function,
- *                               int line, char *string);
- *
- * DESCRIPTION
- *
- *    This is the main function for debug output.  Please note that you should
- *    rather use the wrapper macro SILC_LOG_DEBUG.
- *    If you want to use it anyway, the `file', `function', and `line' are the
- *    corresponding offsets in the source files, while `string' must be a
- *    dynamic allocated (null-terminated) buffer.
- *
- ***/
-void silc_log_output_debug(char *file, const char *function,
-                          int line, char *string);
-
-/****f* silcutil/SilcLogAPI/silc_log_output_hexdump
- *
- * SYNOPSIS
- *
- *    void silc_log_output_hexdump(char *file, char *function,
- *                                 int line, void *data_in,
- *                                 SilcUInt32 len, char *string);
- *
- * DESCRIPTION
- *
- *    This is the main function for hexdump output.  Please note that you
- *    should rather use the wrapper macro SILC_LOG_HEXDUMP.
- *    If you want to use it anyway, the `file', `function', and `line' are the
- *    corresponding offsets in the source files, `data_in' is the beginning
- *    of the buffer you wish to hexdump, which is `len' bytes long.
- *    `string' must be a dynamic allocated (null-terminated) buffer.
- *
- ***/
-void silc_log_output_hexdump(char *file, const char *function,
-                            int line, void *data_in,
-                            SilcUInt32 len, char *string);
+void silc_log_reset_all(void);
 
 /****f* silcutil/SilcLogAPI/silc_log_set_debug_callbacks
  *
@@ -621,15 +419,13 @@ void silc_log_output_hexdump(char *file, const char *function,
  *    output, that will be called with the `debug_context' parameter.
  *    When SilcLog receives a debug message, it will trigger the callback
  *    function.  If the callback function returns TRUE SilcLog will assume
- *    the input as handled and won't run its default handler.
- *    `hexdump_cb' and `hexdump_context' works the same way, except that they
- *    are referred to SILC_LOG_HEXDUMP requests.
- *    You can disable/remove a callback by setting it to NULL.
- *    If set, each callback function must be either in the form described by
- *    SilcLogDebugCb or SilcLogHexdumpCb.
+ *    the input as handled and won't run its default handler.  The `hexdump_cb'
+ *    and `hexdump_context' works the same way, except that they are referred
+ *    to SILC_LOG_HEXDUMP requests.
  *
- * SEE ALSO
- *    SilcLogDebugCb,  SilcLogHexdumpCb
+ *    You can disable/remove a callback by setting it to NULL.  If set, each
+ *    callback function must be either in the form described by SilcLogDebugCb
+ *    or SilcLogHexdumpCb.
  *
  ***/
 void silc_log_set_debug_callbacks(SilcLogDebugCb debug_cb,
@@ -637,6 +433,19 @@ void silc_log_set_debug_callbacks(SilcLogDebugCb debug_cb,
                                  SilcLogHexdumpCb hexdump_cb,
                                  void *hexdump_context);
 
+/****f* silcutil/SilcLogAPI/silc_log_reset_debug_callbacks
+ *
+ * SYNOPSIS
+ *
+ *    void silc_log_reset_debug_callbacks();
+ *
+ * DESCRIPTION
+ *
+ *    Resets debug callbacks set with silc_log_set_debug_callbacks.
+ *
+ ***/
+void silc_log_reset_debug_callbacks(void);
+
 /****f* silcutil/SilcLogAPI/silc_log_set_debug_string
  *
  * SYNOPSIS
@@ -652,4 +461,91 @@ void silc_log_set_debug_callbacks(SilcLogDebugCb debug_cb,
  ***/
 void silc_log_set_debug_string(const char *debug_string);
 
+/****f* silcutil/SilcLogAPI/silc_log_timestamp
+ *
+ * NAME
+ *
+ *    void silc_log_timestamp(bool enable);
+ *
+ * DESCRIPTION
+ *
+ *    Use timestamp in log messages.  Set `enable' to TRUE to enable
+ *    timestamp and to FALSE to disable it.  Default is TRUE.
+ *
+ ***/
+void silc_log_timestamp(bool enable);
+
+/****f* silcutil/SilcLogAPI/silc_log_flushdelay
+ *
+ * NAME
+ *
+ *    void silc_log_flushdelay(SilcUInt32 flushdelay);
+ *
+ * DESCRIPTION
+ *
+ *    Sets the logfiles flushing delay in seconds.  Default is 300 seconds.
+ *
+ ***/
+void silc_log_flushdelay(SilcUInt32 flushdelay);
+
+/****f* silcutil/SilcLogAPI/silc_log_quick
+ *
+ * NAME
+ *
+ *    void silc_log_quick(bool enable);
+ *
+ * DESCRIPTION
+ *
+ *    SilcLog makes use of libc stream buffering output, which means that it
+ *    saves HD activity by buffering the logging messages and writing them
+ *    all together every some minutes (default is 5 minutes).
+ *
+ *    Setting `enable' to TRUE will force SilcLog to write messages to the
+ *    filesystem as soon as they are received. This increases the CPU activity
+ *    notably on bigger servers, but reduces memory usage.
+ *
+ *    If you want to change the logging style on-the-fly, make sure to call
+ *    silc_log_flush_all() after setting `enable'  to TRUE.
+ *
+ *    Default is FALSE.
+ *
+ ***/
+void silc_log_quick(bool enable);
+
+/****v* silcutil/SilcLogAPI/silc_log_debug
+ *
+ * NAME
+ *
+ *    void silc_log_debug(bool enable);
+ *
+ * DESCRIPTION
+ *
+ *    If `enable' is set to FALSE, debugging functions won't procude any
+ *    output and if set to TRUE prints debug messages to stderr.  Default
+ *    is FALSE.
+ *
+ * SEE ALSO
+ *    SILC_LOG_DEBUG
+ *
+ ***/
+void silc_log_debug(bool enable);
+
+/****v* silcutil/SilcLogAPI/silc_log_debug_hexdump
+ *
+ * NAME
+ *
+ *    void silc_log_debug_hexdump(bool enable);
+ *
+ * DESCRIPTION
+ *
+ *    If `enable' is set to FALSE, debugging functions won't produce
+ *    any output anf if set to TRUE prints hexdump debug message to
+ *    stderr.  Default is FALSE.
+ *
+ * SEE ALSO
+ *    SILC_LOG_HEXDUMP
+ *
+ ***/
+void silc_log_debug_hexdump(bool enable);
+
 #endif /* !SILCLOG_H */