How to print $(UNIQUEID) in every Log Line

HI, we need the unique id contained in $(UNIQUEID) variable to be printed in every log statement of the call, that the unique id is associated with.
Currently we tried several approach(using grep, verbose(), log() application) mentioned in this asterisk mail, but couldn’t get it in every log line.
The application, Verbose() and Log(), just prints the id only once, but we need it to be printed in every log corresponding to a call. So that we can debug / trace that call.
We’re using CDR to save the call records, but that is not sufficient to debug the call.
So please tell us, are there any other workaround / ways for this?

Thank you.

There is no configuration or ability to do that. The call identifier[1] is what is used in log messages.


Ok, but that Id is only created after the channel is established between two endpoints, right?.
So I generated an error while calling ( intentionally ) and confirmed that Call Identifier is not printed in logs if some error occurs.
Also why TID ( thread Id ) which is printed along the log level, is not recommended to grep the logs for a particular call?. Can it be duplicate or what?.

A lot of events for a SIP call are handled on the thread that handles incoming SIP requests, rather than the PABX thread. Some events may be the result of scheduled operations run on timers.

1 Like

As well a call identifier won’t exist if a call doesn’t exist in Asterisk, ie: it was rejected early. You wouldn’t have a unique id in that case either.

1 Like

Ok, thank you that clears some doubt I had.
So what I did is modified the logger.c to print the uniqueid and how I got that uniqueid? I made a function in cdr.c to get it. But this is wrong, as it’s values changes and doesn’t persist.
Can you please guide me how can I get uniqueid in logger.c? then this is solved.

Edit : I rectified it using volatile as variable type of a variable, in which I’m saving the uniqueid in cdr.c. Also I tested this using concurrent calls, everything is working as it should.
So just confirming now, am I doing it right? Some tips on this?

We’re waiting for your reply @jcolp @david551.


This isn’t a developer forum.

1 Like

Ok Sorry my bad. I’ll continue this thread in dev community, but I couldn’t find it. Where should I post this query?.
Thanks for helping out!

Edit : Would asterisk dev mailist list do?

If I have anything to add to a thread I do so. You’re in uncharted territory going against how things are currently written.