Solved

Add cookies in the Apache Log.

Posted on 2010-09-21
12
703 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video discusses moving either the default database or any database to a new volume.

707 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

12 Experts available now in Live!

Get 1:1 Help Now