2 * Copyright (c) 1995 - 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
34 #include <arla_local.h>
37 Log_method
* arla_log_method
= NULL
;
38 Log_unit
* arla_log_unit
= NULL
;
41 arla_log(unsigned level
, const char *fmt
, ...)
45 assert (arla_log_method
);
48 log_vlog(arla_log_unit
, level
, fmt
, args
);
54 arla_loginit(char *logname
, log_flags flags
)
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
,
63 if (arla_log_unit
== NULL
)
64 errx (1, "arla_loginit: log_unit_init failed");
65 log_setflags (arla_log_method
, flags
);
69 arla_log_set_level (const char *s
)
71 log_set_mask_str (arla_log_method
, NULL
, s
);
76 arla_log_set_level_num (unsigned level
)
78 log_set_mask (arla_log_unit
, level
);
82 arla_log_get_level (char *s
, size_t len
)
84 log_mask2str (arla_log_method
, NULL
, s
, len
);
88 arla_log_get_level_num (void)
90 return log_get_mask (arla_log_unit
);
98 arla_err (int eval
, unsigned level
, int error
, const char *fmt
, ...)
102 va_start (args
, fmt
);
103 arla_verr (eval
, level
, error
, fmt
, args
);
108 arla_verr (int eval
, unsigned level
, int error
, const char *fmt
, va_list args
)
112 vasprintf (&s
, fmt
, args
);
114 log_log (arla_log_unit
, level
,
115 "Sorry, no memory to print `%s'...", fmt
);
118 log_log (arla_log_unit
, level
, "%s: %s", s
, koerr_gettext (error
));
124 arla_errx (int eval
, unsigned level
, const char *fmt
, ...)
128 va_start (args
, fmt
);
129 arla_verrx (eval
, level
, fmt
, args
);
134 arla_verrx (int eval
, unsigned level
, const char *fmt
, va_list args
)
136 log_vlog (arla_log_unit
, level
, fmt
, args
);
141 arla_warn (unsigned level
, int error
, const char *fmt
, ...)
145 va_start (args
, fmt
);
146 arla_vwarn (level
, error
, fmt
, args
);
151 arla_vwarn (unsigned level
, int error
, const char *fmt
, va_list args
)
155 vasprintf (&s
, fmt
, args
);
157 log_log (arla_log_unit
, level
,
158 "Sorry, no memory to print `%s'...", fmt
);
161 log_log (arla_log_unit
, level
, "%s: %s", s
, koerr_gettext (error
));
166 arla_warnx (unsigned level
, const char *fmt
, ...)
170 va_start (args
, fmt
);
171 arla_vwarnx (level
, fmt
, args
);
176 arla_vwarnx (unsigned level
, const char *fmt
, va_list args
)
178 log_vlog (arla_log_unit
, level
, fmt
, args
);
182 arla_warnx_with_fid (unsigned level
, const VenusFid
*fid
, const char *fmt
, ...)
186 va_start (args
, fmt
);
187 arla_vwarnx_with_fid (level
, fid
, fmt
, args
);
192 arla_vwarnx_with_fid (unsigned level
, const VenusFid
*fid
, const char *fmt
,
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
);
208 log_log (arla_log_unit
, level
,
209 "Sorry, no memory to print `%s'...", fmt
);
212 log_log (arla_log_unit
, level
,
213 "volume %s (%ld) in cell %s (%ld): %s",
214 volname
, (unsigned long)fid
->fid
.Volume
, cellname
,