>grand.central.org GCO Public CellServDB 25 Oct 2007
[arla.git] / arlad / arladeb.c
blobab6d5d99ca7f54826fecf0927e1162b0c18e0edf
1 /*
2 * Copyright (c) 1995 - 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include <arla_local.h>
35 RCSID("$Id$");
37 Log_method* arla_log_method = NULL;
38 Log_unit* arla_log_unit = NULL;
40 void
41 arla_log(unsigned level, const char *fmt, ...)
43 va_list args;
45 assert (arla_log_method);
47 va_start(args, fmt);
48 log_vlog(arla_log_unit, level, fmt, args);
49 va_end(args);
53 void
54 arla_loginit(char *logname, log_flags flags)
56 assert (logname);
58 arla_log_method = log_open("arla", logname);
59 if (arla_log_method == NULL)
60 errx (1, "arla_loginit: log_opened failed with log `%s'", logname);
61 arla_log_unit = log_unit_init (arla_log_method, "arla", arla_deb_units,
62 ARLA_DEFAULT_LOG);
63 if (arla_log_unit == NULL)
64 errx (1, "arla_loginit: log_unit_init failed");
65 log_setflags (arla_log_method, flags);
68 int
69 arla_log_set_level (const char *s)
71 log_set_mask_str (arla_log_method, NULL, s);
72 return 0;
75 void
76 arla_log_set_level_num (unsigned level)
78 log_set_mask (arla_log_unit, level);
81 void
82 arla_log_get_level (char *s, size_t len)
84 log_mask2str (arla_log_method, NULL, s, len);
87 unsigned
88 arla_log_get_level_num (void)
90 return log_get_mask (arla_log_unit);
97 void
98 arla_err (int eval, unsigned level, int error, const char *fmt, ...)
100 va_list args;
102 va_start (args, fmt);
103 arla_verr (eval, level, error, fmt, args);
104 va_end (args);
107 void
108 arla_verr (int eval, unsigned level, int error, const char *fmt, va_list args)
110 char *s;
112 vasprintf (&s, fmt, args);
113 if (s == NULL) {
114 log_log (arla_log_unit, level,
115 "Sorry, no memory to print `%s'...", fmt);
116 exit (eval);
118 log_log (arla_log_unit, level, "%s: %s", s, koerr_gettext (error));
119 free (s);
120 exit (eval);
123 void
124 arla_errx (int eval, unsigned level, const char *fmt, ...)
126 va_list args;
128 va_start (args, fmt);
129 arla_verrx (eval, level, fmt, args);
130 va_end (args);
133 void
134 arla_verrx (int eval, unsigned level, const char *fmt, va_list args)
136 log_vlog (arla_log_unit, level, fmt, args);
137 exit (eval);
140 void
141 arla_warn (unsigned level, int error, const char *fmt, ...)
143 va_list args;
145 va_start (args, fmt);
146 arla_vwarn (level, error, fmt, args);
147 va_end (args);
150 void
151 arla_vwarn (unsigned level, int error, const char *fmt, va_list args)
153 char *s;
155 vasprintf (&s, fmt, args);
156 if (s == NULL) {
157 log_log (arla_log_unit, level,
158 "Sorry, no memory to print `%s'...", fmt);
159 return;
161 log_log (arla_log_unit, level, "%s: %s", s, koerr_gettext (error));
162 free (s);
165 void
166 arla_warnx (unsigned level, const char *fmt, ...)
168 va_list args;
170 va_start (args, fmt);
171 arla_vwarnx (level, fmt, args);
172 va_end (args);
175 void
176 arla_vwarnx (unsigned level, const char *fmt, va_list args)
178 log_vlog (arla_log_unit, level, fmt, args);
181 void
182 arla_warnx_with_fid (unsigned level, const VenusFid *fid, const char *fmt, ...)
184 va_list args;
186 va_start (args, fmt);
187 arla_vwarnx_with_fid (level, fid, fmt, args);
188 va_end(args);
191 void
192 arla_vwarnx_with_fid (unsigned level, const VenusFid *fid, const char *fmt,
193 va_list args)
195 char *s;
196 const char *cellname;
197 char volname[VLDB_MAXNAMELEN];
199 cellname = cell_num2name (fid->Cell);
200 if (cellname == NULL)
201 cellname = "<unknown>";
202 if (volcache_getname (fid->fid.Volume, fid->Cell,
203 volname, sizeof(volname)) != 0)
204 strlcpy(volname, "<unknown>", sizeof(volname));
206 vasprintf (&s, fmt, args);
207 if (s == NULL) {
208 log_log (arla_log_unit, level,
209 "Sorry, no memory to print `%s'...", fmt);
210 return;
212 log_log (arla_log_unit, level,
213 "volume %s (%ld) in cell %s (%ld): %s",
214 volname, (unsigned long)fid->fid.Volume, cellname,
215 (long)fid->Cell, s);
216 free (s);