LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-15-2011, 05:36 AM   #1
markdibley
LQ Newbie
 
Registered: Apr 2010
Posts: 13

Rep: Reputation: 0
Create an Apache log for a particular <location>


Hi

I have an apache server setup where I have different rules using <location>. Essentially, I have a test environment "/test/" and I would like to capture the logs for activity in this location and direct it into a separate log.

I know that perhaps I should have set up virtual hosts, but I wasn't aware of them at the time and the change over can not be accommodated at the moment (the change control wouldn't be agreed). I was wondering if it could be done using environment variables.

At the moment I use

Code:
tail -f /var/log/httpd/error_log | grep "/test/"
but this does miss out some messages, particularly multiple line SOAP messages.

Any suggestions would be welcome. Thanks.

Mark

Last edited by markdibley; 06-15-2011 at 05:46 AM.
 
Old 06-15-2011, 06:48 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

You can use SetEnvIf for this, even though I also think that a virtualhost approach would be a better solution.
Anyway, use in httpd.conf (or whatever .conf file apache uses) the follwoing:
Code:
SetEnvIf Request_URI "^/test/" testlog
and 2 Customlog directives, like:
Code:
CustomLog /path/to/access_log common env=!testlog
Customlog /path/to/test.log common env=testlog
Regards
 
Old 06-15-2011, 08:00 AM   #3
markdibley
LQ Newbie
 
Registered: Apr 2010
Posts: 13

Original Poster
Rep: Reputation: 0
That is great. I had most of the first part, but not the second part.

I presume the ^ in "^/test/" is part of a regex. If so that makes it a very powerful.

I will definitely look at virtual hosts the next time round.

Thanks for the solution.

Mark
 
Old 06-15-2011, 08:31 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
You're welcome.
BTW, you're right: ^ is used in a regex that matches everything that starts with the string following the ^ character

Regards
 
Old 06-15-2011, 11:31 AM   #5
markdibley
LQ Newbie
 
Registered: Apr 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Hello

Sorry to open this up again, but having tried this I realise that CustomLog appears to be logging access logs only. However, it is the ErrorLog that I wish to redirect into separate logs.

Having read further I can see that ErrorLog is non-configurable, but I was wondering if the error is part of an environment variable that I can output using CustomLog.

Thanks again
 
Old 06-16-2011, 12:02 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

Indeed you cannot customize error_log. Anyway if you're using a CustomLog as above (i.e. using the common format), you can filter the test.log based on the response code (penultimate field):
Quote:
192.168.254.1 - - [16/Jun/2011:07:59:54 +0300] "GET /error.htm HTTP/1.1" 404 207
You can create a script to look for a 404 (or better yet, for a 4XX, as all these are error codes) in that field and pipe the output to another file

Regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
In Apache server, How to change log file location and log format for access log fil? since1993 Linux - Server 1 08-19-2009 04:14 PM
system log location tractng Linux - Newbie 3 04-23-2008 02:19 PM
How to create Log messages in /var/log directory ratul_11 Linux - Server 4 03-12-2008 01:23 AM
Location of Gaim Log ZAMO Linux - General 3 07-03-2007 05:18 AM
Boot log location tristanlee85 Fedora 3 10-15-2005 04:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration