OSSP CVS Repository

ossp - ossp-pkg/l2/l2.h 1.1
Not logged in
[Honeypot]  [Browse]  [Directory]  [Home]  [Login
[Reports]  [Search]  [Ticket]  [Timeline
  [Raw

ossp-pkg/l2/l2.h 1.1
/*
**  L2 - OSSP Logging Library
**  Copyright (c) 2001 The OSSP Project (http://www.ossp.org/)
**  Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/)
**
**  This file is part of OSSP L2, a flexible logging library which
**  can be found at http://www.ossp.com/pkg/l2/.
**
**  Permission to use, copy, modify, and distribute this software for
**  any purpose with or without fee is hereby granted, provided that
**  the above copyright notice and this permission notice appear in all
**  copies.
**
**  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
**  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
**  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
**  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
**  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
**  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
**  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
**  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
**  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
**  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
**  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
**  SUCH DAMAGE.
**
**  l2.h: C API
*/

#ifndef __L2_H__
#define __L2_H__

#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

/* forward declarations for opaque data structures */
union  l2_context_un;
struct l2_stream_st;
struct l2_channel_st;
struct l2_handler_st;

/* corresponding data types for data structures */
typedef union  l2_context_un l2_context_t;
typedef struct l2_handler_st l2_handler_t;
typedef struct l2_stream_st  l2_stream_t;
typedef struct l2_channel_st l2_channel_t;

/* list of logging levels */
typedef enum {
    L2_LEVEL_DEBUG,
    L2_LEVEL_TRACE,
    L2_LEVEL_INFO,
    L2_LEVEL_NOTICE,
    L2_LEVEL_WARNING,
    L2_LEVEL_ERROR,
    L2_LEVEL_CRITICAL,
    L2_LEVEL_PANIC
} l2_level_t;

/* list of return values */
typedef enum {
    L2_OK,
    L2_ERROR
} l2_error_t;

/* context union for callbacks */
union l2_context_un {
    int     i;
    long    l;
    float   f;
    double  d;
    void   *vp;
    char   *cp;
};

/* channel handler specification structure */
struct l2_handler_st {
    int (*create)   (l2_context_t *ctx);
    int (*configure)(l2_context_t *ctx, const char *fmt, va_list ap);
    int (*open)     (l2_context_t *ctx, l2_channel_t *below);
    int (*write)    (l2_context_t *ctx, l2_channel_t *below, const char *buf, size_t buf_size);
    int (*flush)    (l2_context_t *ctx, l2_channel_t *below);
    int (*close)    (l2_context_t *ctx, l2_channel_t *below);
    int (*destroy)  (l2_context_t *ctx);
};

/* type of formatter callback function */
typedef int (*l2_formatter_t)(
    l2_context_t *context, 
    const char   *name, 
    const char   *param, 
    char         *buf, 
    size_t        bufsize, 
    va_list       ap
);

/* channel operations */
l2_channel_t *l2_channel_create   (l2_handler_t *h);
l2_channel_t *l2_channel_stack    (l2_channel_t *ch1, l2_channel_t *ch2);
int           l2_channel_configure(l2_channel_t *ch, const char *fmt, ...);
int           l2_channel_open     (l2_channel_t *ch);
int           l2_channel_write    (l2_channel_t *ch, const char *buf, size_t bufsize);
int           l2_channel_flush    (l2_channel_t *ch);
int           l2_channel_close    (l2_channel_t *ch);
int           l2_channel_destroy  (l2_channel_t *ch);

/* stream operations */
l2_stream_t  *l2_stream_create    (void);
l2_stream_t  *l2_stream_channel   (l2_stream_t *st, l2_channel_t *ch, unsigned int levelmask);
l2_stream_t  *l2_stream_formatter (l2_stream_t *st, l2_formatter_t *cb, l2_context_t *ctx);
unsigned int  l2_stream_levels    (l2_stream_t *st, unsigned int levelmask);
void          l2_stream_log       (l2_stream_t *st, unsigned int log_level, const char* fmt, ...);
void          l2_stream_vlog      (l2_stream_t *st, unsigned int log_level, const char* fmt, va_list ap);
void          l2_stream_destroy   (l2_stream_t *st);

#endif /* __L2_H__ */


CVSTrac 2.0.1