version 0.9.6
[rofl0r-htun.git] / include / log.h
blob63bd9fa3047ee81fb920c391a834131f6d026013
1 /* -------------------------------------------------------------------------
2 * log.h - htun logging defs
3 * Copyright (C) 2002 Moshe Jacobson <moshe@runslinux.net>,
4 * Ola Nordström <ola@triblock.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * -------------------------------------------------------------------------
21 /* $Id: log.h,v 2.4 2005/10/27 11:11:10 jehsom Exp $ */
23 #ifndef __LOG_H
24 #define __LOG_H
26 #include <stdio.h>
27 #include <semaphore.h>
29 #define LOGLINE_MAX 1024
31 typedef struct {
32 int fd;
33 sem_t sem;
34 int flags;
35 } log_t;
38 #define DEBUG 1
39 #define INFO 2
40 #define WARN 3
41 #define ERROR 4
42 #define FATAL 5
45 * Logs to the logfile using printf()-like format strings.
47 * log_t - The value you got back from a log_open() call.
48 * level - can be one of: DEBUG, INFO, WARN, ERROR, FATAL
49 * fmt - is a printf()-like format string, followed by the parameters.
51 * Returns 0 on success, or -1 on failure.
53 int lprintf_real( const char *func, log_t *log, unsigned int level, char *fmt, ... );
55 #define lprintf(args...) lprintf_real(__FUNCTION__, ## args)
57 #define LOG_TRUNC 1<<0
58 #define LOG_NODATE 1<<1
59 #define LOG_NOLF 1<<2
60 #define LOG_NOLVL 1<<3
61 #define LOG_DEBUG 1<<4
62 #define LOG_STDERR 1<<5
63 #define LOG_NOTID 1<<6
64 #define LOG_FUNC 1<<7
67 * Initializes the logfile to be written to with fprintf().
69 * fname - The name of the logfile to write to
70 * flags - The bitwise 'or' of zero or more of the following flags:
71 * LOG_TRUNC - Truncates the logfile on opening
72 * LOG_NODATE - Omits the date from each line of the log
73 * LOG_NOLF - Keeps from inserting a trailing '\n' when you don't.
74 * LOG_NOLVL - Keeps from inserting a log level indicator.
75 * LOG_STDERR - Sends log data to stderr as well as to the log.
76 * (this not implemented yet)
78 * Returns NULL on failure, and a valid log_t (value > 0) on success.
80 log_t *log_open( char *fname, int flags );
83 * Closes a logfile when it's no longer needed
85 * log - The log_t corresponding to the log you want to close
87 void log_close( log_t *log );
89 #endif