Add remaining documentation
[libcontrac.git] / src / log.c
1 /** \ingroup contrac
2 * @file
3 * @author David Llewellyn-Jones
4 * @version $(VERSION)
5 *
6 * @section LICENSE
7 *
8 *
9 *
10 * @brief
11 * @section DESCRIPTION
12 *
13 *
14 *
15 */
16
17 // Includes
18
19 #include <time.h>
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <malloc.h>
23
24 #include "contrac/log.h"
25
26 // Defines
27
28 // Structures
29
30 // Function prototypes
31
32 /**
33 * Log a string to syslog.
34 *
35 * In generl, the LOG macro should be used instead.
36 *
37 * Constructs a message using the supplied format and parameters and records it
38 * in the system log. The format is the same as for printf.
39 *
40 * The logging levels are the standard syslog levels:
41 *
42 * LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR, etc.
43 *
44 * @param priority The log level priority.
45 * @param format The format for the message, the same as for printf.
46 * @param ... parameters to combine with the format to create the message.
47 */
48 void log_priority(int priority, const char *format, ...) {
49 va_list args;
50 int length;
51 char *buffer;
52
53 va_start(args, format);
54 length = vsnprintf(NULL, 0, format, args);
55 va_end(args);
56
57 buffer = malloc(sizeof(char) * (length + 1));
58
59 va_start(args, format);
60 length = vsnprintf(buffer, length + 1, format, args);
61 va_end(args);
62 buffer[length] = 0;
63
64 syslog(priority, "%s", buffer);
65 }
66
67 // Function definitions
68