Score:0

How Can I add Cookie value or Session ID Value in ErrorLogFormat of Apache?

nr flag

I want to add the 'my_session' cookie value in the Apache error log. I have added an access log 'LogFormat' as below:

<IfModule mod_ssl.c>

    <VirtualHost *:443>

        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" [%{my_session}C : %{UNIQUE_ID}e]" detailed
        CustomLog ${APACHE_LOG_DIR}/ssl.www.example.com_access.log detailed

        ErrorLogFormat "[%t] [%l] [pid %P] [%{UNIQUE_ID}e] [client %a] %M"
        ErrorLog ${APACHE_LOG_DIR}/ssl.www.example.com_error.log

    </VirtualHost>

</IfModule>

But when I add the same format in 'ErrorLogFormat' then face the error as Unrecognized error log format directive %C:

ErrorLogFormat "[%t] [%l] [pid %P] [%{my_session}C : %{UNIQUE_ID}e] [client %a] %M"

I used 'mod_unique_id' to get a unique request id.

My requirement is only to add SessionId value/Cookie value in Apache Error Log.

Score:0
ru flag

So depending if the Cookie you want to log is in Request or Response heather you just use %{header_name}i or %{header_name}o respectively.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.