base
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define DEFAULT_LOGFILE_PATH "/user/service/logs/new_sh_statusd/"
|
||||
|
||||
char* timeToString(struct tm *t) {
|
||||
static char s[20];
|
||||
sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
|
||||
t->tm_hour, t->tm_min, t->tm_sec
|
||||
);
|
||||
return s;
|
||||
}
|
||||
|
||||
char *makeLogString()
|
||||
{
|
||||
struct tm *t;
|
||||
time_t timer;
|
||||
static char log_path_file[128];
|
||||
|
||||
timer = time(NULL);
|
||||
t = localtime(&timer);
|
||||
|
||||
snprintf(log_path_file, 128, "%ssh_statusd_%04d%02d%02d.log", DEFAULT_LOGFILE_PATH,
|
||||
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday);
|
||||
return log_path_file;
|
||||
}
|
||||
|
||||
char *makeLogString_para(const char *prefix)
|
||||
{
|
||||
struct tm *t;
|
||||
time_t timer;
|
||||
static char log_path_file[128];
|
||||
|
||||
timer = time(NULL);
|
||||
t = localtime(&timer);
|
||||
|
||||
snprintf(log_path_file, 128, "%s%s_%04d%02d%02d.log", DEFAULT_LOGFILE_PATH, prefix,
|
||||
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday);
|
||||
return log_path_file;
|
||||
}
|
||||
|
||||
void WriteSHLog(char *msg, FILE *ifp)
|
||||
{
|
||||
struct tm *t;
|
||||
time_t timer;
|
||||
|
||||
timer = time(NULL);
|
||||
t = localtime(&timer);
|
||||
|
||||
fprintf(ifp, "[%s] %s\n", timeToString(t), msg);
|
||||
fflush(ifp);
|
||||
}
|
||||
Reference in New Issue
Block a user