Methodology for an exception logger

Hello,

I am logging to the eeprom exceptions that may be generated by functions e.g: failure to send an email or failure to to get time from ntp etc. I organized the eeprom into 512 8 byte records, each stores

  1. 'unix time stamp' of the exception (4 bytes)
  2. 'who' is generating the error (1 byte) generally this is a function or a piece of code in a function
  3. 'expected' value (1 byte)
  4. 'actual' actual value (1 byte)
  5. 'extra' unused byte (1 byte)

It works perfectly well and upon start-up I have the ability to dump the eeprom.

My concern is to find a systematic and quasi automatic way for the assignment of the 'who' numbers in such a way that they be unique and, of course that I keep trace of who's who when i make a post mortem analysis

Any suggestion?

Thanks in advance

Use #define's to allocate numbers to function names (#define 10 GET_NTP_TIME) and in the function getNtpTime() you call the error logger with GET_NTP_TIME as the who value.
Keeping all the defines together at top of code makes tracking additions & changes easier than going through several separate functions.

Excellent! Thanks Riva and Delta

Better still, define them all in a single enum declaration, which will ensure they are all unique.

Regards,
Ray L.

RayLivingston:
Better still, define them all in a single enum declaration, which will ensure they are all unique.

Regards,
Ray L.

Can you please give an example?

enum ErrorWho_t
{
    WHO_UNDEFINED,
    WHO_SETUP,           // Error occurred in Setup()
    WHO_LOOP,            // Error occurred in Loop()
    WHO_FUNC1,          // Error occurred in Func1()
    // etc..
};

ErrorWho_t who = WHO_UNDEFINED;

int Func1(int somearg)
{
    // Do whatever...
    if (BlowChunks)
        LogException(WHO_FUNC1, expected, got, extra);
}

This will create symbols for , WHO_UNDEFINED (== 0), WHO_SETUP (== 1), WHO_LOOP (== 2), WHO_FUNC1 (== 3), etc. that you can use just like #defines, and each value will be unique.

Regards,
Ray L.

Thank you Ray,

This gives indeed exclusive codes - may be somewhat difficult to maintain

one can use the macro LINE to log the line number of the code causing the event to be logged