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

Print timestamps in logs #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Print timestamps in logs #70

wants to merge 1 commit into from

Conversation

Xenapte
Copy link

@Xenapte Xenapte commented Dec 19, 2023

I've been using microsocks for a week and the only issue bothering me is the lack of timestamped outputs.

Some additional notes

I've only added timestamps to the dolog macro as this is what I needed the most. Functions calling perror are still not timestamped.

#define LOGTS() { \
char t[20] = {}; struct tm tm_buf; time_t secs = time(NULL); \
strftime(t, sizeof(t), "[%m-%d %T] ", localtime_r(&secs, &tm_buf)); \
fputs(t, stderr); \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use dprintf here too as buffered io isn't threadsafe - at least on glibc. mixing buffered and non-buffered makes the problem even worse.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, LOGTS should be a function to prevent all the code from be expanded at every callsite.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use %Y-%m-%d %T for less ambiguity too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants