1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate /* 7*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996-1999 by Internet Software Consortium. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software for any 10*7c478bd9Sstevel@tonic-gate * purpose with or without fee is hereby granted, provided that the above 11*7c478bd9Sstevel@tonic-gate * copyright notice and this permission notice appear in all copies. 12*7c478bd9Sstevel@tonic-gate * 13*7c478bd9Sstevel@tonic-gate * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 14*7c478bd9Sstevel@tonic-gate * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 15*7c478bd9Sstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 16*7c478bd9Sstevel@tonic-gate * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 17*7c478bd9Sstevel@tonic-gate * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 18*7c478bd9Sstevel@tonic-gate * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 19*7c478bd9Sstevel@tonic-gate * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20*7c478bd9Sstevel@tonic-gate * SOFTWARE. 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 23*7c478bd9Sstevel@tonic-gate 24*7c478bd9Sstevel@tonic-gate #ifndef LOGGING_H 25*7c478bd9Sstevel@tonic-gate #define LOGGING_H 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 28*7c478bd9Sstevel@tonic-gate #include <stdio.h> 29*7c478bd9Sstevel@tonic-gate #include <stdarg.h> 30*7c478bd9Sstevel@tonic-gate #include <unistd.h> 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #define log_critical (-5) 33*7c478bd9Sstevel@tonic-gate #define log_error (-4) 34*7c478bd9Sstevel@tonic-gate #define log_warning (-3) 35*7c478bd9Sstevel@tonic-gate #define log_notice (-2) 36*7c478bd9Sstevel@tonic-gate #define log_info (-1) 37*7c478bd9Sstevel@tonic-gate #define log_debug(level) (level) 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate typedef enum { log_syslog, log_file, log_null } log_channel_type; 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #define LOG_MAX_VERSIONS 99 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #define LOG_CLOSE_STREAM 0x0001 44*7c478bd9Sstevel@tonic-gate #define LOG_TIMESTAMP 0x0002 45*7c478bd9Sstevel@tonic-gate #define LOG_TRUNCATE 0x0004 46*7c478bd9Sstevel@tonic-gate #define LOG_USE_CONTEXT_LEVEL 0x0008 47*7c478bd9Sstevel@tonic-gate #define LOG_PRINT_LEVEL 0x0010 48*7c478bd9Sstevel@tonic-gate #define LOG_REQUIRE_DEBUG 0x0020 49*7c478bd9Sstevel@tonic-gate #define LOG_CHANNEL_BROKEN 0x0040 50*7c478bd9Sstevel@tonic-gate #define LOG_PRINT_CATEGORY 0x0080 51*7c478bd9Sstevel@tonic-gate #define LOG_CHANNEL_OFF 0x0100 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate typedef struct log_context *log_context; 54*7c478bd9Sstevel@tonic-gate typedef struct log_channel *log_channel; 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #define LOG_OPTION_DEBUG 0x01 57*7c478bd9Sstevel@tonic-gate #define LOG_OPTION_LEVEL 0x02 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate #define log_open_stream __log_open_stream 60*7c478bd9Sstevel@tonic-gate #define log_close_stream __log_close_stream 61*7c478bd9Sstevel@tonic-gate #define log_get_stream __log_get_stream 62*7c478bd9Sstevel@tonic-gate #define log_get_filename __log_get_filename 63*7c478bd9Sstevel@tonic-gate #define log_check_channel __log_check_channel 64*7c478bd9Sstevel@tonic-gate #define log_check __log_check 65*7c478bd9Sstevel@tonic-gate #define log_vwrite __log_vwrite 66*7c478bd9Sstevel@tonic-gate #define log_write __log_write 67*7c478bd9Sstevel@tonic-gate #define log_new_context __log_new_context 68*7c478bd9Sstevel@tonic-gate #define log_free_context __log_free_context 69*7c478bd9Sstevel@tonic-gate #define log_add_channel __log_add_channel 70*7c478bd9Sstevel@tonic-gate #define log_remove_channel __log_remove_channel 71*7c478bd9Sstevel@tonic-gate #define log_option __log_option 72*7c478bd9Sstevel@tonic-gate #define log_category_is_active __log_category_is_active 73*7c478bd9Sstevel@tonic-gate #define log_new_syslog_channel __log_new_syslog_channel 74*7c478bd9Sstevel@tonic-gate #define log_new_file_channel __log_new_file_channel 75*7c478bd9Sstevel@tonic-gate #define log_set_file_owner __log_set_file_owner 76*7c478bd9Sstevel@tonic-gate #define log_new_null_channel __log_new_null_channel 77*7c478bd9Sstevel@tonic-gate #define log_inc_references __log_inc_references 78*7c478bd9Sstevel@tonic-gate #define log_dec_references __log_dec_references 79*7c478bd9Sstevel@tonic-gate #define log_get_channel_type __log_get_channel_type 80*7c478bd9Sstevel@tonic-gate #define log_free_channel __log_free_channel 81*7c478bd9Sstevel@tonic-gate #define log_close_debug_channels __log_close_debug_channels 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate FILE * log_open_stream(log_channel); 84*7c478bd9Sstevel@tonic-gate int log_close_stream(log_channel); 85*7c478bd9Sstevel@tonic-gate FILE * log_get_stream(log_channel); 86*7c478bd9Sstevel@tonic-gate char * log_get_filename(log_channel); 87*7c478bd9Sstevel@tonic-gate int log_check_channel(log_context, int, log_channel); 88*7c478bd9Sstevel@tonic-gate int log_check(log_context, int, int); 89*7c478bd9Sstevel@tonic-gate #ifdef __GNUC__ 90*7c478bd9Sstevel@tonic-gate void log_vwrite(log_context, int, int, const char *, 91*7c478bd9Sstevel@tonic-gate va_list args) 92*7c478bd9Sstevel@tonic-gate __attribute__((__format__(__printf__, 4, 0))); 93*7c478bd9Sstevel@tonic-gate void log_write(log_context, int, int, const char *, ...) 94*7c478bd9Sstevel@tonic-gate __attribute__((__format__(__printf__, 4, 5))); 95*7c478bd9Sstevel@tonic-gate #else 96*7c478bd9Sstevel@tonic-gate void log_vwrite(log_context, int, int, const char *, 97*7c478bd9Sstevel@tonic-gate va_list args); 98*7c478bd9Sstevel@tonic-gate void log_write(log_context, int, int, const char *, ...); 99*7c478bd9Sstevel@tonic-gate #endif 100*7c478bd9Sstevel@tonic-gate int log_new_context(int, char **, log_context *); 101*7c478bd9Sstevel@tonic-gate void log_free_context(log_context); 102*7c478bd9Sstevel@tonic-gate int log_add_channel(log_context, int, log_channel); 103*7c478bd9Sstevel@tonic-gate int log_remove_channel(log_context, int, log_channel); 104*7c478bd9Sstevel@tonic-gate int log_option(log_context, int, int); 105*7c478bd9Sstevel@tonic-gate int log_category_is_active(log_context, int); 106*7c478bd9Sstevel@tonic-gate log_channel log_new_syslog_channel(unsigned int, int, int); 107*7c478bd9Sstevel@tonic-gate log_channel log_new_file_channel(unsigned int, int, const char *, 108*7c478bd9Sstevel@tonic-gate FILE *, unsigned int, 109*7c478bd9Sstevel@tonic-gate unsigned long); 110*7c478bd9Sstevel@tonic-gate int log_set_file_owner(log_channel, uid_t, gid_t); 111*7c478bd9Sstevel@tonic-gate log_channel log_new_null_channel(void); 112*7c478bd9Sstevel@tonic-gate int log_inc_references(log_channel); 113*7c478bd9Sstevel@tonic-gate int log_dec_references(log_channel); 114*7c478bd9Sstevel@tonic-gate log_channel_type log_get_channel_type(log_channel); 115*7c478bd9Sstevel@tonic-gate int log_free_channel(log_channel); 116*7c478bd9Sstevel@tonic-gate void log_close_debug_channels(log_context); 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate #endif /* !LOGGING_H */ 119