~awe/phablet-extras/ofono-nettime-plugin

« back to all changes in this revision

Viewing changes to src/log.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2009-08-15 15:55:11 UTC
  • Revision ID: james.westby@ubuntu.com-20090815155511-frst06dijguhyfi4
Tags: upstream-0.3
ImportĀ upstreamĀ versionĀ 0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  oFono - Open Source Telephony
 
4
 *
 
5
 *  Copyright (C) 2008-2009  Intel Corporation. All rights reserved.
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License version 2 as
 
9
 *  published by the Free Software Foundation.
 
10
 *
 
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.
 
15
 *
 
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 *
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <stdarg.h>
 
27
#include <syslog.h>
 
28
 
 
29
#include "ofono.h"
 
30
 
 
31
static volatile gboolean debug_enabled = FALSE;
 
32
 
 
33
/**
 
34
 * ofono_info:
 
35
 * @format: format string
 
36
 * @Varargs: list of arguments
 
37
 *
 
38
 * Output general information
 
39
 */
 
40
void ofono_info(const char *format, ...)
 
41
{
 
42
        va_list ap;
 
43
 
 
44
        va_start(ap, format);
 
45
 
 
46
        vsyslog(LOG_INFO, format, ap);
 
47
 
 
48
        va_end(ap);
 
49
}
 
50
 
 
51
/**
 
52
 * ofono_warn:
 
53
 * @format: format string
 
54
 * @Varargs: list of arguments
 
55
 *
 
56
 * Output warning messages
 
57
 */
 
58
void ofono_warn(const char *format, ...)
 
59
{
 
60
        va_list ap;
 
61
 
 
62
        va_start(ap, format);
 
63
 
 
64
        vsyslog(LOG_WARNING, format, ap);
 
65
 
 
66
        va_end(ap);
 
67
}
 
68
 
 
69
/**
 
70
 * ofono_error:
 
71
 * @format: format string
 
72
 * @varargs: list of arguments
 
73
 *
 
74
 * Output error messages
 
75
 */
 
76
void ofono_error(const char *format, ...)
 
77
{
 
78
        va_list ap;
 
79
 
 
80
        va_start(ap, format);
 
81
 
 
82
        vsyslog(LOG_ERR, format, ap);
 
83
 
 
84
        va_end(ap);
 
85
}
 
86
 
 
87
/**
 
88
 * ofono_debug:
 
89
 * @format: format string
 
90
 * @varargs: list of arguments
 
91
 *
 
92
 * Output debug message
 
93
 *
 
94
 * The actual output of the debug message is controlled via a command line
 
95
 * switch. If not enabled, these messages will be ignored.
 
96
 */
 
97
void ofono_debug(const char *format, ...)
 
98
{
 
99
        va_list ap;
 
100
 
 
101
        if (debug_enabled == FALSE)
 
102
                return;
 
103
 
 
104
        va_start(ap, format);
 
105
 
 
106
        vsyslog(LOG_DEBUG, format, ap);
 
107
 
 
108
        va_end(ap);
 
109
}
 
110
 
 
111
void __ofono_toggle_debug(void)
 
112
{
 
113
        if (debug_enabled == TRUE)
 
114
                debug_enabled = FALSE;
 
115
        else
 
116
                debug_enabled = TRUE;
 
117
}
 
118
 
 
119
int __ofono_log_init(gboolean detach, gboolean debug)
 
120
{
 
121
        int option = LOG_NDELAY | LOG_PID;
 
122
 
 
123
        if (detach == FALSE)
 
124
                option |= LOG_PERROR;
 
125
 
 
126
        openlog("ofonod", option, LOG_DAEMON);
 
127
 
 
128
        syslog(LOG_INFO, "oFono version %s", VERSION);
 
129
 
 
130
        debug_enabled = debug;
 
131
 
 
132
        return 0;
 
133
}
 
134
 
 
135
void __ofono_log_cleanup(void)
 
136
{
 
137
        syslog(LOG_INFO, "Exit");
 
138
 
 
139
        closelog();
 
140
}