Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timestamp to WARN and DEBUG messages #221

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/msg_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* Create an externally visible msg_queue object that will be read with ptrace.
* It will be read by ulp_messages (tools/messages.c) using ptrace. */
Expand Down Expand Up @@ -139,6 +140,17 @@ msgq_vpush(const char *format, va_list arglist)
void
ulp_warn(const char *format, ...)
{
time_t rawtime;
struct tm *timeinfo, local_tm;
char timestamp[32];

time(&rawtime);
timeinfo = localtime_r(&rawtime, &local_tm);

size_t n = strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo);
if (n > 0)
msgq_strpush(timestamp, n + 1);

va_list args;
va_start(args, format);
msgq_vpush(format, args);
Expand All @@ -148,6 +160,17 @@ ulp_warn(const char *format, ...)
void
ulp_debug(const char *format, ...)
{
time_t rawtime;
struct tm *timeinfo, local_tm;
char timestamp[32];

time(&rawtime);
timeinfo = localtime_r(&rawtime, &local_tm);

size_t n = strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo);
if (n > 0)
msgq_strpush(timestamp, n + 1);

va_list args;
va_start(args, format);
msgq_vpush(format, args);
Expand Down
22 changes: 22 additions & 0 deletions tools/introspection.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ void
ulp_warn(const char *format, ...)
{
if (!ulp_quiet) {
time_t rawtime;
struct tm *timeinfo, local_tm;
char timestamp[32];

time(&rawtime);
timeinfo = localtime_r(&rawtime, &local_tm);

strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo);

fputs(timestamp, stderr);

va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
Expand All @@ -97,6 +108,17 @@ void
ulp_debug(const char *format, ...)
{
if (ulp_verbose) {
time_t rawtime;
struct tm *timeinfo, local_tm;
char timestamp[32];

time(&rawtime);
timeinfo = localtime_r(&rawtime, &local_tm);

strftime(timestamp, 32, "[%Y-%m-%d %H:%M:%S] ", timeinfo);

fputs(timestamp, stderr);

va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
Expand Down
Loading