Here are the basic things you need to determine:
- Trace levels (e.g. debugging, alerts, warnings, information, critical, etc.). You must also set the current trace level, so if the current trace level is INFO, then all messages with a trace level above the information will be printed. If the current trace level is critical, only critical messages will be printed.
enum _TraceLevelType { INFO = 0, DEBUG, WARNING, ERROR, CRITICAL } TraceLevelType;
- Error codes, I think the best way is to have a large enumerator. Something like that:
enum _ErrorType {
- Message queue You must have a mechanism in which everyone can send messages, and these messages are in the queue. Since you are working on embedded systems, this is very important. You do not want to waste time debugging messages in real-time. Thus, the thread that manages the error codes should have a very low priority, and all received messages should be sent to the queue, so when the scheduler decides to call it, you do printfs to the console or to any output that you decide.
So your error method would be something like this:
TraceError(TraceLevelType traceLevel, ErrorType errorType, char *msg) { if(CURRENT_TRACE_LEVEL <= traceLevel) else }
You may also have more options indicating which module is sending the error, but I think that is basically it.
source share