Annotation of embedaddon/libpdel/sys/alog.h, revision 1.1

1.1     ! misho       1: 
        !             2: /*
        !             3:  * Copyright (c) 2001-2002 Packet Design, LLC.
        !             4:  * All rights reserved.
        !             5:  * 
        !             6:  * Subject to the following obligations and disclaimer of warranty,
        !             7:  * use and redistribution of this software, in source or object code
        !             8:  * forms, with or without modifications are expressly permitted by
        !             9:  * Packet Design; provided, however, that:
        !            10:  * 
        !            11:  *    (i)  Any and all reproductions of the source or object code
        !            12:  *         must include the copyright notice above and the following
        !            13:  *         disclaimer of warranties; and
        !            14:  *    (ii) No rights are granted, in any manner or form, to use
        !            15:  *         Packet Design trademarks, including the mark "PACKET DESIGN"
        !            16:  *         on advertising, endorsements, or otherwise except as such
        !            17:  *         appears in the above copyright notice or in the software.
        !            18:  * 
        !            19:  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
        !            20:  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
        !            21:  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
        !            22:  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
        !            23:  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
        !            24:  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
        !            25:  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
        !            26:  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
        !            27:  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
        !            28:  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
        !            29:  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
        !            30:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
        !            31:  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
        !            32:  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
        !            33:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
        !            35:  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
        !            36:  * THE POSSIBILITY OF SUCH DAMAGE.
        !            37:  *
        !            38:  * Author: Archie Cobbs <archie@freebsd.org>
        !            39:  */
        !            40: 
        !            41: #ifndef _PDEL_SYS_ALOG_H_
        !            42: #define _PDEL_SYS_ALOG_H_
        !            43: 
        !            44: #include <sys/types.h>
        !            45: #include <sys/time.h>
        !            46: 
        !            47: #include <stdarg.h>
        !            48: #include <regex.h>
        !            49: 
        !            50: #ifndef __FreeBSD__
        !            51: #define __printflike(x,y)
        !            52: #endif
        !            53: 
        !            54: /*
        !            55:  * Simple support for logging channels. Each channel can log to
        !            56:  * standard error, local syslog, or remote syslog, and has a minimum
        !            57:  * log severity filter.
        !            58:  */
        !            59: 
        !            60: #define ALOG_MAX_CHANNELS      16      /* max number of channels */
        !            61: 
        !            62: /*
        !            63:  * This structure is used to configure a channel.
        !            64:  */
        !            65: struct alog_config {
        !            66:        const char      *path;          /* logfile filename, or NULL for none */
        !            67:        const char      *name;          /* syslog id, or null to disable */
        !            68:        const char      *facility;      /* syslog facility, null for stderr */
        !            69:        struct in_addr  remote_server;  /* remote server, or 0.0.0.0 local */
        !            70:        int             min_severity;   /* min severity to actually log */
        !            71:        int             histlen;        /* how many history entries to save */
        !            72: };
        !            73: 
        !            74: /* Entries in the log history are returned in this form */
        !            75: struct alog_entry {
        !            76:        time_t  when;                   /* when event was logged */
        !            77:        int     sev;                    /* entry log severity */
        !            78:        char    msg[0];                 /* entry contents (including NUL) */
        !            79: };
        !            80: 
        !            81: DEFINE_STRUCTS_ARRAY(alog_history, struct alog_entry *);
        !            82: 
        !            83: __BEGIN_DECLS
        !            84: 
        !            85: /*
        !            86:  * Initialize or reconfigure a logging channel.
        !            87:  *
        !            88:  *     channel         Between zero and ALOG_MAX_CHANNELS - 1.
        !            89:  *     conf            Channel configuration.
        !            90:  */
        !            91: extern int     alog_configure(int channel, const struct alog_config *conf);
        !            92: 
        !            93: /*
        !            94:  * Reset a logging channel.
        !            95:  */
        !            96: extern int     alog_shutdown(int channel);
        !            97: 
        !            98: /*
        !            99:  * Set current logging channel.
        !           100:  */
        !           101: extern int     alog_set_channel(int channel);
        !           102: 
        !           103: /*
        !           104:  * Enable/disable debugging on a channel. Everything logged to the
        !           105:  * channel will be logged to stderr as well.
        !           106:  */
        !           107: extern void    alog_set_debug(int channel, int enabled);
        !           108: 
        !           109: /*
        !           110:  * Get a selection from the log history.
        !           111:  *
        !           112:  * The caller's structs array is filled in and is an array of
        !           113:  * pointers to struct alog_entry.
        !           114:  *
        !           115:  * Caller should free the returned array by calling
        !           116:  * "structs_free(&alog_history_type, NULL, list)".
        !           117:  */
        !           118: extern int     alog_get_history(int channel, int min_severity,
        !           119:                        int max_entries, time_t max_age,
        !           120:                        const regex_t *preg, struct alog_history *list);
        !           121: 
        !           122: /*
        !           123:  * Clear (i.e., forget) log history.
        !           124:  */
        !           125: extern int     alog_clear_history(int channel);
        !           126: 
        !           127: /*
        !           128:  * Log to the currently active logging channel. Preserves errno.
        !           129:  */
        !           130: extern void    alog(int sev, const char *fmt, ...) __printflike(2, 3);
        !           131: extern void    valog(int sev, const char *fmt,
        !           132:                        va_list args) __printflike(2, 0);
        !           133: 
        !           134: /*
        !           135:  * Convert between numeric syslog facility and string.
        !           136:  */
        !           137: extern int     alog_facility(const char *name);
        !           138: const char     *alog_facility_name(int facility);
        !           139: 
        !           140: /*
        !           141:  * Convert between numeric syslog severity and string.
        !           142:  */
        !           143: extern int     alog_severity(const char *name);
        !           144: const char     *alog_severity_name(int sev);
        !           145: 
        !           146: /*
        !           147:  * Expand '%m' in a format string.
        !           148:  *
        !           149:  * Returns a pointer to a static buffer.
        !           150:  */
        !           151: extern void    alog_expand(const char *fmt,
        !           152:                        int errnum, char *buf, size_t bufsize);
        !           153: 
        !           154: /* Some useful alog "structs" types */
        !           155: extern const struct structs_type       alog_facility_type;
        !           156: extern const struct structs_type       alog_severity_type;
        !           157: extern const struct structs_type       alog_config_type;
        !           158: extern const struct structs_type       alog_history_type;
        !           159: 
        !           160: __END_DECLS
        !           161: 
        !           162: /* Handy macro for a common usage */
        !           163: #ifdef __GNUC__
        !           164: #define alogf(sev, fmt, arg...)        alog(sev, "%s: " fmt, __FUNCTION__ , ## arg)
        !           165: #else
        !           166: #define alogf                  alog
        !           167: #endif
        !           168: 
        !           169: #endif /* _PDEL_SYS_ALOG_H_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>