1 /***************************************************************************** |
|
2 * Copyright (C) 2014 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of the mbsePi-apps |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * mbsePi-apps is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with EC-65K; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 #include "mash.h" |
|
24 #include "xutil.h" |
|
25 #include "logger.h" |
|
26 |
|
27 |
|
28 void logger(char *filename, char *progname, char *data) |
|
29 { |
|
30 struct timeval now; |
|
31 struct tm ptm; |
|
32 char *outstr = NULL, *name = NULL; |
|
33 FILE *logfile; |
|
34 |
|
35 name = xstrcpy((char *)"/var/local/log/"); |
|
36 name = xstrcat(name, progname); |
|
37 name = xstrcat(name, (char *)"/"); |
|
38 name = xstrcat(name, filename); |
|
39 |
|
40 gettimeofday(&now, NULL); |
|
41 localtime_r(&now.tv_sec, &ptm); |
|
42 |
|
43 if ((logfile = fopen(name, "a+"))) { |
|
44 outstr = calloc(10240, sizeof(char)); |
|
45 snprintf(outstr, 10239, "%04d-%02d-%02d %02d:%02d,%s\n", ptm.tm_year + 1900, ptm.tm_mon + 1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, data); |
|
46 fprintf(logfile, outstr); |
|
47 fclose(logfile); |
|
48 free(outstr); |
|
49 outstr = NULL; |
|
50 } else { |
|
51 syslog(LOG_NOTICE, "logger: cannot open %s for writing", name); |
|
52 } |
|
53 |
|
54 free(name); |
|
55 name = NULL; |
|
56 } |
|
57 |
|
58 |
|