1 /* $Id$
2  *
3  * Lasso - A free implementation of the Liberty Alliance specifications.
4  *
5  * Copyright (C) 2004-2007 Entr'ouvert
6  * http://lasso.entrouvert.org
7  *
8  * Authors: See AUTHORS file in top-level directory.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "logging.h"
25 #include "lasso_config.h"
26 #include <glib.h>
27 #include <time.h>
28 
29 void
lasso_log(GLogLevelFlags level,const char * filename,int line,const char * function,const char * format,...)30 lasso_log(GLogLevelFlags level, const char *filename, int line,
31 		const char *function, const char *format, ...)
32 {
33 	char debug_string[1024];
34 	time_t ts;
35 	char date[20];
36 	va_list args;
37 
38 	va_start(args, format);
39 	g_vsnprintf(debug_string, 1024, format, args);
40 	va_end(args);
41 
42 	time(&ts);
43 	strftime(date, 20, "%Y-%m-%d %H:%M:%S", localtime(&ts));
44 
45 	if (level == G_LOG_LEVEL_DEBUG || level == G_LOG_LEVEL_CRITICAL) {
46 		g_log(LASSO_LOG_DOMAIN, level, "%s (%s/%s:%d) %s",
47 				date, filename, function, line, debug_string);
48 	} else {
49 		g_log(LASSO_LOG_DOMAIN, level, "%s\t%s", date, debug_string);
50 	}
51 }
52 
53 int
lasso_log_error_code(G_GNUC_UNUSED GLogLevelFlags level,int error,...)54 lasso_log_error_code(G_GNUC_UNUSED GLogLevelFlags level, int error, ...)
55 {
56 	const char *format;
57 	char message[1024];
58 	va_list args;
59 
60 	format = lasso_strerror(error);
61 
62 	va_start(args, error);
63 	g_vsnprintf(message, 1024, format, args);
64 	va_end(args);
65 
66 	return error;
67 }
68