Add time in console

This commit is contained in:
def 2017-08-04 22:38:22 +02:00
parent 77ca505e74
commit 5d8a0ddc1e
5 changed files with 23 additions and 14 deletions

View file

@ -192,11 +192,8 @@ void dbg_msg(const char *sys, const char *fmt, ...)
int len;
//str_format(str, sizeof(str), "[%08x][%s]: ", (int)time(0), sys);
time_t rawtime;
char timestr[80];
time(&rawtime);
str_timestamp_ex(rawtime, timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S");
str_timestamp_format(timestr, sizeof(timestr), FORMAT_SPACE);
#if !defined(CONF_PLATFORM_MACOSX)
if(dbg_msg_threaded)
@ -2227,22 +2224,26 @@ int str_hex_decode(unsigned char *dst, int dst_size, const char *src)
void str_timestamp_ex(time_t time_data, char *buffer, int buffer_size, const char *format)
{
struct tm *time_info;
time_info = localtime(&time_data);
strftime(buffer, buffer_size, format, time_info);
buffer[buffer_size-1] = 0; /* assure null termination */
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
void str_timestamp(char *buffer, int buffer_size)
void str_timestamp_format(char *buffer, int buffer_size, const char *format)
{
time_t time_data;
time(&time_data);
str_timestamp_ex(time_data, buffer, buffer_size, "%Y-%m-%d_%H-%M-%S");
str_timestamp_ex(time_data, buffer, buffer_size, format);
}
void str_timestamp(char *buffer, int buffer_size)
{
str_timestamp_format(buffer, buffer_size, FORMAT_NOSPACE);
}
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
void str_escape(char **dst, const char *src, const char *end)
{
while(*src && *dst + 1 < end)

View file

@ -1062,9 +1062,14 @@ int str_hex_decode(unsigned char *dst, int dst_size, const char *src);
- Guarantees that buffer string will contain zero-termination.
*/
void str_timestamp(char *buffer, int buffer_size);
void str_timestamp_format(char *buffer, int buffer_size, const char *format);
void str_timestamp_ex(time_t time, char *buffer, int buffer_size, const char *format)
GNUC_ATTRIBUTE((format(strftime, 4, 0)));
#define FORMAT_TIME "%H:%M:%S"
#define FORMAT_SPACE "%Y-%m-%d %H:%M:%S"
#define FORMAT_NOSPACE "%Y-%m-%d_%H-%M-%S"
/*
Function: str_escape
Escapes \ and " characters in a string.

View file

@ -142,5 +142,5 @@ void sqlstr::GetTimeStamp(char *pDest, unsigned int Size)
std::time_t Rawtime;
std::time(&Rawtime);
str_timestamp_ex(Rawtime, pDest, Size, "%Y-%m-%d %H:%M:%S");
str_timestamp_ex(Rawtime, pDest, Size, FORMAT_SPACE);
}

View file

@ -248,8 +248,11 @@ void CConsole::Print(int Level, const char *pFrom, const char *pStr, bool Highli
{
if(Level <= m_aPrintCB[i].m_OutputLevel && m_aPrintCB[i].m_pfnPrintCallback)
{
char aTimeBuf[80];
str_timestamp_format(aTimeBuf, sizeof(aTimeBuf), FORMAT_TIME);
char aBuf[1024];
str_format(aBuf, sizeof(aBuf), "[%s]: %s", pFrom, pStr);
str_format(aBuf, sizeof(aBuf), "[%s][%s]: %s", aTimeBuf, pFrom, pStr);
m_aPrintCB[i].m_pfnPrintCallback(aBuf, m_aPrintCB[i].m_pPrintCallbackUserdata, Highlighted);
}
}

View file

@ -803,7 +803,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
UI()->DoLabelScaled(&Left, Localize("Created:"), 14.0f, -1);
char aTimestamp[256];
str_timestamp_ex(m_lDemos[m_DemolistSelectedIndex].m_Date, aTimestamp, sizeof(aTimestamp), "%Y-%m-%d %H:%M:%S");
str_timestamp_ex(m_lDemos[m_DemolistSelectedIndex].m_Date, aTimestamp, sizeof(aTimestamp), FORMAT_SPACE);
UI()->DoLabelScaled(&Right, aTimestamp, 14.0f, -1);
Labels.HSplitTop(5.0f, 0, &Labels);
@ -1116,7 +1116,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
Cursor.m_LineWidth = Button.w;
char aBuf[256];
str_timestamp_ex(r.front().m_Date, aBuf, sizeof(aBuf), "%Y-%m-%d %H:%M:%S");
str_timestamp_ex(r.front().m_Date, aBuf, sizeof(aBuf), FORMAT_SPACE);
TextRender()->TextEx(&Cursor, aBuf, -1);
}
}