aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/logger.h
blob: 8656edfffc1044613bd79cf9ebc8fe625a3f6744 (plain)
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
/**
 * @file logger.h
 * 
 * @brief Logger object, allows fine-controlled logging
 * 
 */

/*
 * Copyright (C) 2005 Jan Hutter, Martin Willi
 * Hochschule fuer Technik Rapperswil
 *
 * 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * 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.
 */

#ifndef LOGGER_H_
#define LOGGER_H_

#include "types.h"

/**
 * Log Levels supported by the logger object
 */
typedef enum logger_level_e logger_level_t;

enum logger_level_e {
	/**
	 * basic control messages
	 */
	CONTROL = 1,
	/**
	 * detailed control messages
	 */
	CONTROL_MORE = 2,
	/**
	 * raw data dumps not containing private data
	 */
	RAW = 4,
	/**
	 * private data dumps
	 */
	PRIVATE = 8
};

/**
 * @brief The logger object
 */
typedef struct logger_s logger_t;
struct logger_s { 
	
	/**
	 * loggs an entry
	 * 
	 * function is used like printf
	 * 
	 * @param this logger_t-object
	 * @param loglevel loglevel of specific log entry
	 * @param format printf like format string
	 * @param ... printf like parameters 
	 * @return SUCCESS
	 */
	status_t (*log) (logger_t *this, logger_level_t log_level, char *format, ...);

	/**
	 * enables a loglevel for the current logger_t-object
	 * 
	 * @param this logger_t-object
	 * @param log_level loglevel to enable
	 * @return SUCCESS
	 */
	status_t (*enable_level) (logger_t *this, logger_level_t log_level);

	/**
	 * disables a loglevel for the current logger_t-object
	 * 
	 * @param this logger_t-object
	 * @param log_level loglevel to disable
	 * @return SUCCESS
	 */	
	status_t (*disable_level) (logger_t *this, logger_level_t log_level);
	
	/**
	 * @brief destroys a logger_t object
	 * 
	 * @param this logger_t object
	 * @return SUCCESS if succeeded, FAILED otherwise
	 */
	status_t (*destroy) (logger_t *this);
};

/**
 * Constructor to create a logger_t-object
 * 
 * @param logger_name Name for the logger_t-object
 * @param file FILE pointer to write the log-messages to. If NULL
 * 		  syslogger is used.
 * @param log_level to assign to the new logger_t-object
 * @return logger_t-object or NULL if failed
 */
logger_t *logger_create(char *logger_name, char *file, logger_level_t log_level);

#endif /*LOGGER_H_*/