File: log.h

package info (click to toggle)
libdebian-installer 0.50
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 1,900 kB
  • ctags: 702
  • sloc: sh: 8,774; ansic: 4,576; makefile: 211
file content (110 lines) | stat: -rw-r--r-- 3,249 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * log.h
 *
 * Copyright (C) 2003 Bastian Blank <waldi@debian.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $Id: log.h 29603 2005-07-31 16:10:46Z cjwatson $
 */

#ifndef DEBIAN_INSTALLER__LOG_H
#define DEBIAN_INSTALLER__LOG_H

#include <stdarg.h>

/**
 * @addtogroup di_log
 * @{
 */

/**
 * @brief Log levels and other flags
 */
typedef enum
{
  DI_LOG_FLAG_FATAL             = 1 << 1,       /**< flag as fatal */

  DI_LOG_LEVEL_ERROR            = 1 << 2,       /**< error level, always fatal */
  DI_LOG_LEVEL_CRITICAL         = 1 << 3,       /**< critical level */
  DI_LOG_LEVEL_WARNING          = 1 << 4,       /**< warning level */
  DI_LOG_LEVEL_MESSAGE          = 1 << 5,       /**< message level */
  DI_LOG_LEVEL_INFO             = 1 << 6,       /**< information level */
  DI_LOG_LEVEL_DEBUG            = 1 << 7,       /**< debug level */
  DI_LOG_LEVEL_OUTPUT           = 1 << 8,       /**< command output */

  DI_LOG_LEVEL_MASK             = ~DI_LOG_FLAG_FATAL,   /**< defines mask for levels */
  DI_LOG_FATAL_MASK             = DI_LOG_LEVEL_ERROR,   /**< defines always fatal levels */
}
di_log_level_flags;

typedef void di_log_handler (di_log_level_flags log_level, const char *message, void *user_data);

/**
 * logs an error
 */
#define di_error(format...) di_log (DI_LOG_LEVEL_ERROR, format)
/**
 * logs a warning
 */
#define di_warning(format...) di_log (DI_LOG_LEVEL_WARNING, format)
/**
 * logs information
 */
#define di_info(format...) di_log (DI_LOG_LEVEL_INFO, format)
/**
 * logs debug info
 */
#define di_debug(format...) di_log (DI_LOG_LEVEL_DEBUG, format)

/**
 * Logs the resolved formatstring with log_level
 *
 * @param log_level the level of the message
 * @param format printf compatible format
 */
void di_log (di_log_level_flags log_level, const char *format, ...) __attribute__ ((format(printf,2,3)));
/**
 * Logs the resolved formatstring with log_level
 *
 * @param log_level the level of the message
 * @param format printf compatible format
 * @param args variable arguments list
 */
void di_vlog (di_log_level_flags log_level, const char *format, va_list args);

/**
 * Sets a log handler
 *
 * @param log_levels levels
 * @param log_func the log handler
 * @param user_data data for log_func
 */
unsigned int di_log_set_handler (di_log_level_flags log_levels, di_log_handler *log_func, void *user_data);

di_log_handler
  /**
   * Default log handler.
   * Logs to STDOUT and STDERR.
   */
  di_log_handler_default,
  /**
   * SYSLOG log handler.
   * Logs to SYSLOG.
   */
  di_log_handler_syslog;

/** @} */
#endif