projects
/
psensor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
improved status icon in hicolor theme to fit well with white background. (LP: #1310323).
[psensor.git]
/
src
/
lib
/
log.c
diff --git
a/src/lib/log.c
b/src/lib/log.c
index
3072474
..
9df4629
100644
(file)
--- a/
src/lib/log.c
+++ b/
src/lib/log.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2010-201
3
jeanfi@gmail.com
+ * Copyright (C) 2010-201
4
jeanfi@gmail.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@
-16,15
+16,21
@@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
+#define _LARGEFILE_SOURCE 1
+#include "config.h"
+
#include <locale.h>
#include <libintl.h>
#define _(str) gettext(str)
#include <stdarg.h>
#include <stdio.h>
#include <locale.h>
#include <libintl.h>
#define _(str) gettext(str)
#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/time.h>
#include <sys/time.h>
+#include <time.h>
#include "log.h"
#include "log.h"
+#include "ptime.h"
static FILE *file;
int log_level = LOG_WARN;
static FILE *file;
int log_level = LOG_WARN;
@@
-51,9
+57,8
@@
void log_close()
#define LOG_BUFFER 4096
static void vlogf(int lvl, const char *fmt, va_list ap)
{
#define LOG_BUFFER 4096
static void vlogf(int lvl, const char *fmt, va_list ap)
{
- struct timeval tv;
char buffer[1 + LOG_BUFFER];
char buffer[1 + LOG_BUFFER];
- char *lvl_str;
+ char *lvl_str
, *t
;
FILE *stdf;
if (lvl > LOG_INFO && (!file || lvl > log_level))
FILE *stdf;
if (lvl > LOG_INFO && (!file || lvl > log_level))
@@
-62,9
+67,6
@@
static void vlogf(int lvl, const char *fmt, va_list ap)
vsnprintf(buffer, LOG_BUFFER, fmt, ap);
buffer[LOG_BUFFER] = '\0';
vsnprintf(buffer, LOG_BUFFER, fmt, ap);
buffer[LOG_BUFFER] = '\0';
- if (gettimeofday(&tv, NULL) != 0)
- timerclear(&tv);
-
switch (lvl) {
case LOG_WARN:
lvl_str = "[WARN]";
switch (lvl) {
case LOG_WARN:
lvl_str = "[WARN]";
@@
-82,9
+84,15
@@
static void vlogf(int lvl, const char *fmt, va_list ap)
lvl_str = "[??]";
}
lvl_str = "[??]";
}
+ t = get_time_str();
+ if (!t)
+ return ;
+
if (file && lvl <= log_level) {
if (file && lvl <= log_level) {
- fprintf(file, "[%
ld] %s %s\n", tv.tv_sec
, lvl_str, buffer);
+ fprintf(file, "[%
s] %s %s\n", t
, lvl_str, buffer);
fflush(file);
fflush(file);
+ } else {
+ t = NULL;
}
if (lvl <= LOG_INFO) {
}
if (lvl <= LOG_INFO) {
@@
-93,8
+101,11
@@
static void vlogf(int lvl, const char *fmt, va_list ap)
else
stdf = stdout;
else
stdf = stdout;
- fprintf(stdf, "[%ld] %s %s\n", tv.tv_sec, lvl_str, buffer);
+
+ fprintf(stdf, "[%s] %s %s\n", t, lvl_str, buffer);
}
}
+
+ free(t);
}
void log_printf(int lvl, const char *fmt, ...)
}
void log_printf(int lvl, const char *fmt, ...)