2011-07-25 07:25:33 +02:00
|
|
|
/*
|
|
|
|
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** This program 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 General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2011-12-01 20:17:23 +01:00
|
|
|
#include "mu-guile-util.h"
|
2011-07-25 07:48:21 +02:00
|
|
|
#include "mu-guile-log.h"
|
2011-07-25 07:25:33 +02:00
|
|
|
|
|
|
|
enum _LogType {
|
|
|
|
LOG_INFO,
|
|
|
|
LOG_WARNING,
|
|
|
|
LOG_CRITICAL
|
|
|
|
};
|
|
|
|
typedef enum _LogType LogType;
|
|
|
|
|
|
|
|
|
|
|
|
static SCM
|
|
|
|
write_log (LogType logtype, SCM FRM, SCM ARGS)
|
|
|
|
#define FUNC_NAME __FUNCTION__
|
|
|
|
{
|
|
|
|
SCM str;
|
2011-12-01 20:17:23 +01:00
|
|
|
|
2011-07-25 07:25:33 +02:00
|
|
|
SCM_ASSERT (scm_is_string(FRM), FRM, SCM_ARG1, "<write_log>");
|
|
|
|
SCM_VALIDATE_REST_ARGUMENT(ARGS);
|
2011-12-01 20:17:23 +01:00
|
|
|
|
2011-07-25 07:25:33 +02:00
|
|
|
str = scm_simple_format (SCM_BOOL_F, FRM, ARGS);
|
2011-12-01 20:17:23 +01:00
|
|
|
|
2011-07-25 07:25:33 +02:00
|
|
|
if (scm_is_string (str)) {
|
|
|
|
|
|
|
|
gchar *output;
|
|
|
|
output = scm_to_utf8_string (str);
|
2011-12-01 20:17:23 +01:00
|
|
|
|
2011-07-25 07:25:33 +02:00
|
|
|
switch (logtype) {
|
|
|
|
case LOG_INFO: g_message ("%s", output); break;
|
|
|
|
case LOG_WARNING: g_warning ("%s", output); break;
|
|
|
|
case LOG_CRITICAL: g_critical ("%s", output); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SCM_UNSPECIFIED;
|
|
|
|
|
|
|
|
#undef FUNC_NAME
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-01 20:17:23 +01:00
|
|
|
SCM_DEFINE_PUBLIC (log_info, "mu:log:info", 1, 0, 1, (SCM FRM, SCM ARGS),
|
2011-07-25 07:25:33 +02:00
|
|
|
"log some message using a list of ARGS applied to FRM "
|
|
|
|
"(in 'simple-format' notation).\n")
|
|
|
|
#define FUNC_NAME s_info
|
|
|
|
{
|
|
|
|
return write_log (LOG_INFO, FRM, ARGS);
|
|
|
|
}
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
2011-12-01 20:17:23 +01:00
|
|
|
SCM_DEFINE_PUBLIC (log_warning, "mu:log:warning", 1, 0, 1, (SCM FRM, SCM ARGS),
|
2011-07-25 07:25:33 +02:00
|
|
|
"log some warning using a list of ARGS applied to FRM (in 'simple-format' "
|
|
|
|
"notation).\n")
|
|
|
|
#define FUNC_NAME s_warning
|
|
|
|
{
|
|
|
|
return write_log (LOG_WARNING, FRM, ARGS);
|
|
|
|
}
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
2011-12-01 20:17:23 +01:00
|
|
|
SCM_DEFINE_PUBLIC (log_critical, "mu:log:critical", 1, 0, 1, (SCM FRM, SCM ARGS),
|
2011-07-25 07:25:33 +02:00
|
|
|
"log some critical message using a list of ARGS applied to FRM "
|
|
|
|
"(in 'simple-format' notation).\n")
|
|
|
|
#define FUNC_NAME s_critical
|
|
|
|
{
|
|
|
|
return write_log (LOG_CRITICAL, FRM, ARGS);
|
|
|
|
}
|
|
|
|
#undef FUNC_NAME
|
|
|
|
|
|
|
|
|
|
|
|
void*
|
2011-07-25 07:48:21 +02:00
|
|
|
mu_guile_log_init (void *data)
|
2011-12-01 20:17:23 +01:00
|
|
|
{
|
2011-07-25 07:48:21 +02:00
|
|
|
#include "mu-guile-log.x"
|
2011-07-25 07:25:33 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|