Skip to content

Commit

Permalink
Add time in console
Browse files Browse the repository at this point in the history
  • Loading branch information
def- committed Aug 4, 2017
1 parent 77ca505 commit 5d8a0dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
21 changes: 11 additions & 10 deletions src/base/system.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/base/system.h
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/engine/server/sql_string_helpers.cpp
Expand Up @@ -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);
}
5 changes: 4 additions & 1 deletion src/engine/shared/console.cpp
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/components/menus_demo.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 5d8a0dd

Please sign in to comment.