documentation for UcxLogger

Wed, 24 Jul 2013 14:26:17 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 24 Jul 2013 14:26:17 +0200
changeset 129
61edec666928
parent 128
b79b1ce438dd
child 130
633f15ce2ee4

documentation for UcxLogger

ucx/list.h file | annotate | diff | comparison | revisions
ucx/logging.h file | annotate | diff | comparison | revisions
     1.1 --- a/ucx/list.h	Tue Jul 23 14:43:45 2013 +0200
     1.2 +++ b/ucx/list.h	Wed Jul 24 14:26:17 2013 +0200
     1.3 @@ -60,10 +60,13 @@
     1.4          for (UcxList* elem = list ; elem != NULL ; elem = elem->next)
     1.5  
     1.6  /**
     1.7 - * UCX list type
     1.8 + * UCX list type.
     1.9   * @see UcxList
    1.10   */
    1.11  typedef struct UcxList UcxList;
    1.12 +/**
    1.13 + * UCX list structure.
    1.14 + */
    1.15  struct UcxList {
    1.16      /**
    1.17       * List element payload.
    1.18 @@ -105,6 +108,7 @@
    1.19   * argument for the <code>data</code> parameter, if you want the copy_func() to
    1.20   * make use of the allocator.
    1.21   * 
    1.22 + * @param allocator the allocator to use
    1.23   * @param list the list to copy
    1.24   * @param cpyfnc a pointer to the function that shall copy an element (may be
    1.25   * <code>NULL</code>)
     2.1 --- a/ucx/logging.h	Tue Jul 23 14:43:45 2013 +0200
     2.2 +++ b/ucx/logging.h	Wed Jul 24 14:26:17 2013 +0200
     2.3 @@ -25,7 +25,12 @@
     2.4   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     2.5   * POSSIBILITY OF SUCH DAMAGE.
     2.6   */
     2.7 -
     2.8 +/**
     2.9 + * Logging API.
    2.10 + * 
    2.11 + * @file   logging.h
    2.12 + * @author Mike Becker, Olaf Wintermann
    2.13 + */
    2.14  #ifndef UCX_LOGGING_H
    2.15  #define UCX_LOGGING_H
    2.16  
    2.17 @@ -39,37 +44,169 @@
    2.18  #endif
    2.19  
    2.20  /* leave enough space for custom log levels */
    2.21 +/** Log level for error messages. */
    2.22  #define UCX_LOGGER_ERROR        0x00
    2.23 +/** Log level for warning messages. */
    2.24  #define UCX_LOGGER_WARN         0x10
    2.25 +/** Log level for information messages. */
    2.26  #define UCX_LOGGER_INFO         0x20
    2.27 -#define UCX_LOGGER_TRACE        0x30
    2.28 +/** Log level for debug messages. */
    2.29 +#define UCX_LOGGER_DEBUG        0x30
    2.30 +/** Log level for trace messages. */
    2.31 +#define UCX_LOGGER_TRACE        0x40
    2.32  
    2.33 +/**
    2.34 + * Output flag for the log level. 
    2.35 + * If this flag is set, the log message will contain the log level.
    2.36 + * @see UcxLogger.mask
    2.37 + */
    2.38  #define UCX_LOGGER_LEVEL        0x01
    2.39 +/**
    2.40 + * Output flag for the timestmap.
    2.41 + * If this flag is set, the log message will contain the timestmap.
    2.42 + * @see UcxLogger.mask
    2.43 + */
    2.44  #define UCX_LOGGER_TIMESTAMP    0x02
    2.45 +/**
    2.46 + * Output flag for the source.
    2.47 + * If this flag is set, the log message will contain the source file and line
    2.48 + * number.
    2.49 + * @see UcxLogger.mask
    2.50 + */
    2.51  #define UCX_LOGGER_SOURCE       0x04
    2.52  
    2.53 +/**
    2.54 + * The UCX Logger object.
    2.55 + */
    2.56  typedef struct {
    2.57 +    /** The stream this logger writes its messages to.*/
    2.58      void *stream;
    2.59 +    /**
    2.60 +     * The write function that shall be used.
    2.61 +     * For standard file or stdout loggers this might be standard fwrite
    2.62 +     * (default).
    2.63 +     */
    2.64      write_func writer;
    2.65 +    /**
    2.66 +     * The date format for timestamp outputs
    2.67 +     * (default: <code>"%F %T %z "</code>).
    2.68 +     * @see UCX_LOGGER_TIMESTAMP
    2.69 +     */
    2.70      char *dateformat;
    2.71 +    /**
    2.72 +     * The level, this logger operates on.
    2.73 +     * If a log command is issued, the message will only be logged, if the log
    2.74 +     * level of the message is less or equal than the log level of the logger.
    2.75 +     */
    2.76      unsigned int level;
    2.77 +    /**
    2.78 +     * A configuration mask for automatic output. 
    2.79 +     * For each flag that is set, the logger automatically outputs some extra
    2.80 +     * information like the timestamp or the source file and line number.
    2.81 +     * See the documentation for the flags for details.
    2.82 +     */
    2.83      unsigned int mask;
    2.84 +    /**
    2.85 +     * A map of valid log levels for this logger.
    2.86 +     * 
    2.87 +     * The keys represent all valid log levels and the values provide string
    2.88 +     * representations, that are used, if the UCX_LOGGER_LEVEL flag is set.
    2.89 +     * 
    2.90 +     * The exact data types are <code>unsigned int</code> for the key and
    2.91 +     * <code>const char*</code> for the value.
    2.92 +     * 
    2.93 +     * @see UCX_LOGGER_LEVEL
    2.94 +     */
    2.95      UcxMap* levels;
    2.96  } UcxLogger;
    2.97  
    2.98 +/**
    2.99 + * Creates a new logger.
   2.100 + * @param stream the stream, which the logger shall write to
   2.101 + * @param level the level on which the logger shall operate
   2.102 + * @param mask configuration mask (cf. UcxLogger.mask)
   2.103 + * @return a new logger object
   2.104 + */
   2.105  UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask);
   2.106 +/**
   2.107 + * Destroys the logger.
   2.108 + * 
   2.109 + * The map containing the valid log levels is also automatically destroyed.
   2.110 + * 
   2.111 + * @param logger the logger to destroy
   2.112 + */
   2.113  void ucx_logger_free(UcxLogger* logger);
   2.114  
   2.115 +/**
   2.116 + * Internal log function - use macros instead.
   2.117 + * 
   2.118 + * This function uses the <code>format</code> and variadic arguments for a
   2.119 + * printf()-style output of the log message.
   2.120 + * 
   2.121 + * Dependent on the UcxLogger.mask some information is prepended. The complete
   2.122 + * format is:
   2.123 + * 
   2.124 + * <code>[LEVEL] [TIMESTAMP] [SOURCEFILE]:[LINENO] message</code>
   2.125 + * 
   2.126 + * @param logger the logger to use
   2.127 + * @param level the level to log on
   2.128 + * @param file information about the source file
   2.129 + * @param line information about the source line number
   2.130 + * @param format format string
   2.131 + * @param ... arguments
   2.132 + * @see ucx_logger_log()
   2.133 + */
   2.134  void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file,
   2.135          const unsigned int line, const char* format, ...);
   2.136 +
   2.137 +/**
   2.138 + * Logs a message at the specified level.
   2.139 + * @param logger the logger to use
   2.140 + * @param level the level to log the message on
   2.141 + * @param ... format string and arguments
   2.142 + * @see ucx_logger_logf()
   2.143 + */
   2.144  #define ucx_logger_log(logger, level, ...) \
   2.145      ucx_logger_logf(logger, level, __FILE__, __LINE__, __VA_ARGS__)
   2.146 +
   2.147 +/**
   2.148 + * Shortcut for logging an error message.
   2.149 + * @param logger the logger to use
   2.150 + * @param ... format string and arguments
   2.151 + * @see ucx_logger_logf()
   2.152 + */
   2.153  #define ucx_logger_error(logger, ...) \
   2.154      ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
   2.155 +/**
   2.156 + * Shortcut for logging an information message.
   2.157 + * @param logger the logger to use
   2.158 + * @param ... format string and arguments
   2.159 + * @see ucx_logger_logf()
   2.160 + */
   2.161  #define ucx_logger_info(logger, ...) \
   2.162      ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
   2.163 +/**
   2.164 + * Shortcut for logging a warning message.
   2.165 + * @param logger the logger to use
   2.166 + * @param ... format string and arguments
   2.167 + * @see ucx_logger_logf()
   2.168 + */
   2.169  #define ucx_logger_warn(logger, ...) \
   2.170      ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
   2.171 +/**
   2.172 + * Shortcut for logging a debug message.
   2.173 + * @param logger the logger to use
   2.174 + * @param ... format string and arguments
   2.175 + * @see ucx_logger_logf()
   2.176 + */
   2.177 +#define ucx_logger_debug(logger, ...) \
   2.178 +    ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__)
   2.179 +/**
   2.180 + * Shortcut for logging a trace message.
   2.181 + * @param logger the logger to use
   2.182 + * @param ... format string and arguments
   2.183 + * @see ucx_logger_logf()
   2.184 + */
   2.185  #define ucx_logger_trace(logger, ...) \
   2.186      ucx_logger_log(logger, UCX_LOGGER_TRACE, __VA_ARGS__)
   2.187  

mercurial