Author Topic: Debug/trace/log structure (library)  (Read 645 times)

0 Members and 1 Guest are viewing this topic.

Offline ricko_ukTopic starter

  • Super Contributor
  • ***
  • Posts: 1015
  • Country: gb
Debug/trace/log structure (library)
« on: July 01, 2021, 10:03:48 pm »
Hi,
there are plenty of debug, trace, log functions already built in most development environments but I have written my own wrapper which adds functionality. Basically it is a single function where I pass the values/fields listed below then I can do all sorts of logging, printing based on all sorts of filtering to affects its behaviour during debug or build.

- time since start (or OS ticks)
- level (Error, warning, debug, info, log)
- comment
- file
- function
- line (sometimes redundant if you use function but not always)
- software break (yes/no)
- up to 5 parameters (uint32 that I can use to log any info/variable)

Then through #defines I can decide different behaviours. For example in debug I can customise that function to print to the console all messages from a certain function after a specific time. Or again as another example, in release mode store into a uSD card all data that has a level of "Log" together with the associated parameters.

My questions are:
1) have any of you done something similar or do you know of similar libraries?
2) any suggestions/feedback on the concept and/or what would u add?

Thank you :)
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14476
  • Country: fr
Re: Debug/trace/log structure (library)
« Reply #1 on: July 01, 2021, 10:46:19 pm »
1. Yes I've done something similar. Like many of us have, I'm sure. I don't think I've ever used a third-party library for this. I'm sure there are tons out there.

2. Well, I don't know what you want to achieve/what kind of info you'd like to have. So it's hard to answer. What I can say though (and that I have implemented) is having code profiling features is handy. I wrote a profiler lib for C. You can define named sections of code to track, and the lib will store execution time, number of executions, etc... for each section. Sections to profile can be nested. Then the lib computes statistics on this (for instance it will compute the min, max, average and std deviation of execution time for each section) and stores the report in a file at the end of program's execution. In the report, it also sorts results according to various criterions. Very handy. GCC has a profiling abilities too, but you must use specific compile options for this, and it doesn't give as much info as my lib, so I rarely use it. (Saying that for those who would reply: but why implement your own since GCC has this!)

 

Offline ricko_ukTopic starter

  • Super Contributor
  • ***
  • Posts: 1015
  • Country: gb
Re: Debug/trace/log structure (library)
« Reply #2 on: July 02, 2021, 12:05:32 am »
Thank you Silicon Wizzard,
having code profiling would be good (I added the __FUNCTION__ for that, but how do you make it more granular? How do you know which section you are in?

Thank you
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf