Skip to main content

Timeline for Logger module in C

Current License: CC BY-SA 4.0

23 events
when toggle format what by license comment
Nov 18, 2020 at 14:44 history edited chux CC BY-SA 4.0
deleted 813 characters in body
Nov 18, 2020 at 14:33 vote accept 766F6964
Nov 18, 2020 at 14:32 comment added 766F6964 Yeah, the second version of the log_general function results in the expected behaviour. :)
Nov 18, 2020 at 12:02 comment added chux @766F6964 On review, I am more certain that my initial lack of va_copy with a 2nd vsnprintf() call is the oops. va_copy appears necessary. What are your results?
Nov 18, 2020 at 11:55 history edited chux CC BY-SA 4.0
Alternate with `va_copy`
Nov 18, 2020 at 11:51 comment added chux @766F6964 1) I am confident that some form of va_..., vsprintf() will work where the lion share of code is in log_general(). 2) I, so far, failed to reproduce your failing output 3) As answered "va_list parameter is tricky" It is easy to post something that "works", yet not portable. 4) log_general() may need to use va_copy(). See posted alternate code - both work for me.
Nov 18, 2020 at 11:49 history edited chux CC BY-SA 4.0
Alternate with `va_copy`
Nov 17, 2020 at 14:50 comment added 766F6964 The compiler options are the default ones of gcc. Essentially just running gcc -o logger logger.c. I was also able to reproduce the same problem on a different machine (Ubuntu VM). The code is exactly yours, 1:1. I'll play around with some more compiler options and see if that helps to pinpoint the problem.
Nov 17, 2020 at 14:43 comment added chux @766F6964 Certainly it is related to passing args1. Will review later. I can not see the .png right now. Hopefully it shows your code and what compiler/options you used. If not, is the code exactly as posted here? What compiler/options used?
Nov 17, 2020 at 14:07 comment added 766F6964 Something is wrong with your example. I tried running exactly your codes, and it messes up the formatting/parameters that are passed to it: i.imgur.com/fpSUDFj.png I really wonder what causes this behaviour? My original solution did not suffer from this problem. As for the color codes, maybe it makes sense to use the termcap library for this as suggested below, or at least store all color codes in an enum or an array.
Nov 17, 2020 at 2:39 comment added chux The whole ANSI color sequences deserves abstraction. Perhaps later.
Nov 17, 2020 at 1:07 comment added chux @766F6964 I did not reproduce your problem. Try a cut/paste of posted code of this answer.
Nov 17, 2020 at 1:03 history edited chux CC BY-SA 4.0
deleted 85 characters in body
Nov 16, 2020 at 16:18 history edited chux CC BY-SA 4.0
Added log_warning() code
Nov 16, 2020 at 15:58 history edited chux CC BY-SA 4.0
added 45 characters in body
Nov 16, 2020 at 15:56 comment added 766F6964 I figured out that va_start(args1, format_string); was missing in the log_warning function. However, it seems that the parameter is interpreted incorrectly as it renders to gibberish: i.imgur.com/WVXNq5s.png
Nov 16, 2020 at 15:48 comment added chux @766F6964 I can review code later today. BTW, did you code &args1 as above?
Nov 16, 2020 at 15:44 comment added 766F6964 Thanks for the detailled feedback. Definitely helpful! I am currently trying to work through your example, and I noticed that int len = vsnprintf(NULL, 0, format_string, *arg); segfaults for me when providing a single string with an integer value.
Nov 16, 2020 at 14:28 history edited chux CC BY-SA 4.0
added 141 characters in body
Nov 16, 2020 at 5:05 history edited chux CC BY-SA 4.0
added 1314 characters in body
Nov 16, 2020 at 4:36 history edited chux CC BY-SA 4.0
added 7 characters in body
Nov 16, 2020 at 4:30 history edited chux CC BY-SA 4.0
added 2 characters in body
Nov 16, 2020 at 4:24 history answered chux CC BY-SA 4.0