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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999-2001, 2005, 2007, 2009-2012 Free Software
Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <string.h>
#include <mailutils/diag.h>
#include <mailutils/nls.h>
#include <mailutils/errno.h>
#include <mailutils/stdstream.h>
#include <mailutils/stream.h>
const char *mu_program_name;
const char *mu_full_program_name;
void
mu_set_program_name (const char *name)
{
const char *progname;
mu_full_program_name = name;
if (!name)
progname = name;
else
{
progname = strrchr (name, '/');
if (progname)
progname++;
else
progname = name;
if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
progname += 3;
}
mu_program_name = progname;
}
void
mu_diag_init ()
{
if (!mu_strerr)
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
}
void
mu_diag_voutput (int level, const char *fmt, va_list ap)
{
mu_diag_init ();
mu_stream_printf (mu_strerr, "\033s<%d>", level);
mu_stream_vprintf (mu_strerr, fmt, ap);
mu_stream_write (mu_strerr, "\n", 1, NULL);
}
void
mu_diag_output (int level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_diag_voutput (level, fmt, ap);
va_end (ap);
}
void
mu_diag_at_locus (int level, struct mu_locus const *loc, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_stream_printf (mu_strerr, "\033f<%d>%s\033l<%u>\033c<%u>",
(unsigned) strlen (loc->mu_file), loc->mu_file,
loc->mu_line,
loc->mu_col);
mu_diag_voutput (level, fmt, ap);
va_end (ap);
}
void
mu_diag_vprintf (int level, const char *fmt, va_list ap)
{
mu_diag_init ();
mu_stream_printf (mu_strerr, "\033<%d>", level);
mu_stream_vprintf (mu_strerr, fmt, ap);
}
void
mu_diag_cont_vprintf (const char *fmt, va_list ap)
{
mu_diag_init ();
mu_stream_vprintf (mu_strerr, fmt, ap);
}
void
mu_diag_printf (int level, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_diag_vprintf (level, fmt, ap);
va_end (ap);
}
void
mu_diag_cont_printf (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
mu_diag_cont_vprintf (fmt, ap);
va_end (ap);
}
const char *
mu_diag_level_to_string (int level)
{
switch (level)
{
case MU_DIAG_EMERG:
return _("emergency");
case MU_DIAG_ALERT:
return _("alert");
case MU_DIAG_CRIT:
return _("critical");
case MU_DIAG_ERROR:
return _("error");
case MU_DIAG_WARNING:
return _("warning");
case MU_DIAG_NOTICE:
return _("notice");
case MU_DIAG_INFO:
return _("info");
case MU_DIAG_DEBUG:
return _("debug");
}
return _("unknown");
}
void
mu_diag_funcall (mu_log_level_t level, const char *func,
const char *arg, int err)
{
if (err)
/* TRANSLATORS: First %s stands for function name, second for its
arguments, third one for the actual error message. */
mu_diag_output (level, _("%s(%s) failed: %s"), func, arg ? arg : "",
mu_strerror (err));
else
/* TRANSLATORS: First %s stands for function name, second for its
arguments. */
mu_diag_output (level, _("%s(%s) failed"), func, arg ? arg : "");
}
|