Solved

Add cookies in the Apache Log.

Posted on 2010-09-21
12
716 Views
Last Modified: 2012-05-10
I would like to have a cookie coming from my client or a new value in there place in my log file.

I'm using a Apache2 and mod-perl.

0
Comment
Question by:oleber
  • 6
  • 5
12 Comments
 
LVL 10

Author Comment

by:oleber
ID: 33725246
The question is:

how do I do it?
0
 
LVL 10

Author Comment

by:oleber
ID: 33725269
in the access and log error
0
 
LVL 57

Expert Comment

by:giltjr
ID: 33733222
Cookies should only come from a browser if you place them in there.

Why do you want cookies to show up in your log if you are the one placing them there?

I'll double check, but I'm not aware of anyway that you can do this.
0
 
LVL 10

Author Comment

by:oleber
ID: 33733356
I don't care why, just how.

I want to be able of grouping every write to the log files. Since the code is all done, t is to expansive to go to every log line and add one identifier.

For now, my best solution was to do a wrapper around the $r in Perl and rewrite the log stuff. Is there something better, that means generic and easy to implement?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 33733576
I was trying to figure out why you want to do this to see if there is another possible option than filling the log with cookies.

According to:

http://www.wellho.net/mouth/1761_Logging-Cookies-with-the-Apache-httpd-web-server.html

You can use "%{Cookie}i"
0
 
LVL 10

Author Comment

by:oleber
ID: 33733667
That works correctly over the access log.

Now the problem is the error log.

How do I set that value in there?

Note: Don't need to come from a cookie, since all my calls pass from a common place.
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 57

Expert Comment

by:giltjr
ID: 33733871
I'm looking for error log stuff.

You can also use:

%{Foobar}C

Where Foobar is the name of the specific cookie you want to log.

Ref: http://httpd.apache.org/docs/current/mod/mod_log_config.html#formats
0
 
LVL 57

Accepted Solution

by:
giltjr earned 125 total points
ID: 33733889
If you read the "Modifiers" section in the above reference you will find:

Particular items can be restricted to print only for responses with specific HTTP status codes by placing a comma-separated list of status codes immediately following the "%". For example, "%400,501{User-agent}i" logs User-agent on 400 errors and 501 errors only. For other status codes, the literal string "-" will be logged. The status code list may be preceded by a "!" to indicate negation: "%!200,304,302{Referer}i" logs Referer  on all requests that do not return one of the three specified codes.

So if you have specific errors, you want to log the cookie values on, you should be able to do that.  I am assuming that they appear in the error log.
0
 
LVL 10

Author Comment

by:oleber
ID: 33735762
OK, I am able of configure this over the access_log, but I'm not able of configure over the error log.

Do you have any idea how to do it?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 33736260
I can seem to find a way customize what is sent to the error log.
0
 
LVL 10

Author Closing Comment

by:oleber
ID: 33763497
seems that just in the new version of apache this will be possible in the access log
0
 
LVL 61

Expert Comment

by:gheist
ID: 33768208
you can not customize error log.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now