OpenVAS Manager  7.0.3~git
logf.h
Go to the documentation of this file.
1 /* OpenVAS Manager log printing facility.
2  * $Id$
3  * Description: A printf like macro for logging communication.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  *
8  * Copyright:
9  * Copyright (C) 2009 Greenbone Networks GmbH
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
31 #ifndef OPENVAS_MANAGER_LOG_H
32 #define OPENVAS_MANAGER_LOG_H
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <sys/types.h>
37 #include <unistd.h>
38 #include <glib.h>
39 
46 #define LOG 0
47 
51 #define LOG_FILE OPENVAS_LOG_DIR "/openvasmd.comm"
52 
53 #if LOG
54 extern FILE* log_stream;
55 
61 #define logf(args...) \
62  do { \
63  if (log_stream) \
64  { \
65  fprintf (log_stream, "%7i ", (int) getpid()); \
66  fprintf (log_stream, args); \
67  if (fflush (log_stream) == EOF) \
68  { \
69  fclose (log_stream); \
70  log_stream = 0; \
71  g_warning ("%s: fflush failed, so turned off comm logging: %s\n", \
72  __FUNCTION__, \
73  strerror (errno)); \
74  } \
75  } \
76  } while (0)
77 #else
78 
81 #define logf(format, args...)
82 #endif
83 
84 #endif