mirror of
https://github.com/albfan/miraclecast.git
synced 2025-03-09 23:38:56 +00:00
log messages with time in human readable way
This commit is contained in:
parent
380504b0f8
commit
72f61549d9
15 changed files with 144 additions and 29 deletions
|
|
@ -32,6 +32,9 @@
|
|||
#include "ctl.h"
|
||||
#include "shl_macro.h"
|
||||
#include "shl_util.h"
|
||||
#include "shl_log.h"
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
/* *sigh* readline doesn't include all their deps, so put them last */
|
||||
#include <readline/history.h>
|
||||
|
|
@ -73,6 +76,37 @@ void cli_printv(const char *fmt, va_list args)
|
|||
rl_redisplay();
|
||||
}
|
||||
|
||||
long long sec, usec;
|
||||
time_t now;
|
||||
struct tm *timeinfo;
|
||||
struct timeval tv;
|
||||
char buffertmp[80];
|
||||
char buffer[80];
|
||||
int millisec;
|
||||
|
||||
|
||||
log__time(&sec, &usec);
|
||||
|
||||
if (log_date_time) {
|
||||
gettimeofday(&tv, NULL);
|
||||
millisec = lrint(tv.tv_usec/1000.0);
|
||||
if (millisec>=1000) {
|
||||
millisec -=1000;
|
||||
tv.tv_sec++;
|
||||
}
|
||||
|
||||
time(&now);
|
||||
timeinfo = localtime(&now);
|
||||
|
||||
strftime(buffertmp, 80, "%x - %X.%03d", timeinfo);
|
||||
sprintf(buffer, "%s.%03d", buffertmp, millisec);
|
||||
}
|
||||
|
||||
if (log_date_time)
|
||||
printf("[%s] ", buffer);
|
||||
else if (log__have_time())
|
||||
printf("[%.4lld.%.6lld] ", sec, usec);
|
||||
|
||||
vprintf(fmt, args);
|
||||
|
||||
if (async) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue