You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by robert rottermann <ro...@redcor.ch> on 2006/01/02 16:12:57 UTC

[users@httpd] how can I add SERVER_NAME to a filename

Hi there,

I would like to
use a construct like the following

    ServerAdmin robert@redcor.net
    ServerName projekte2.fh-aargau.ch
    CustomLog     /var/log/apache2/%{SERVER_NAME}.log combined
    ErrorLog      /var/log/apache2/%{SERVER_NAME}.log

However, the filename it creates is %{SERVER_NAME}.log instead of 
projekte2.fh-aargau.ch.log


how can I achieve the desired result?

thanks
robert


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] how can I add SERVER_NAME to a filename

Posted by Eugene <li...@fsck.net>.
On Mon, Jan 02, 2006 at 12:01:33PM CST, robert rottermann <ro...@redcor.ch> wrote:
: 
: I was a bit unclear. I know that I can name the files like this
: 
: CustomLog /var/log/apache2/projekte2.fh-aargau.ch/com_log combined
: 
: however I would like to have the "projekte2.fh-aargau.ch" part
: replaced by a variable.
: Is this possible?
: 
: somehow %{SERVER_NAME} must be known as I use it in a rewrite rule.

AFAIK, what you're asking for cannot be done in Apache.

Those variables that are availble in RewriteRule are exposed
thanks to mod_rewrite.  The same server variables exposed by
mod_rewrite are not available in other Apache directives.


-- 
Eugene

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] how can I add SERVER_NAME to a filename

Posted by ht...@karsites.net.
Yes - I think it is possible.

This is part of the apache official httpd.conf file:

#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
#    CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
#</VirtualHost>

Not the last entries for the log files.
I don't know how they implement it though.
Are they some sort of environment, or CGI variables?
Maybe someone else knows?

I'd be interested to know how it is done.

Keith


On Mon, 2 Jan 2006, robert rottermann wrote:

> To: users@httpd.apache.org
> From: robert rottermann <ro...@redcor.ch>
> Subject: Re: [users@httpd] how can I add SERVER_NAME to a filename
> 
> keith,
> thank you very much for your answer.
> I was a bit unclear. I know that I can name the files like this
> 
> CustomLog /var/log/apache2/projekte2.fh-aargau.ch/com_log combined
> 
> however I would like to have the "projekte2.fh-aargau.ch" part
> replaced by a variable.
> Is this possible?
> 
> somehow %{SERVER_NAME} must be known as I use it in a rewrite rule.
> 
> thanks
> robert

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] how can I add SERVER_NAME to a filename

Posted by ht...@karsites.net.
Have you looked at mod_setenvif ?

Keith


On Mon, 2 Jan 2006, robert rottermann wrote:

> To: users@httpd.apache.org
> From: robert rottermann <ro...@redcor.ch>
> Subject: Re: [users@httpd] how can I add SERVER_NAME to a filename
> 
> keith,
> thank you very much for your answer.
> I was a bit unclear. I know that I can name the files like this
> 
> CustomLog /var/log/apache2/projekte2.fh-aargau.ch/com_log combined
> 
> however I would like to have the "projekte2.fh-aargau.ch" part
> replaced by a variable.
> Is this possible?
> 
> somehow %{SERVER_NAME} must be known as I use it in a rewrite rule.
> 
> thanks
> robert

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] how can I add SERVER_NAME to a filename

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
robert rottermann wrote:
> keith,
> thank you very much for your answer.
> I was a bit unclear. I know that I can name the files like this
> 
> CustomLog /var/log/apache2/projekte2.fh-aargau.ch/com_log combined
> 
> however I would like to have the "projekte2.fh-aargau.ch" part
> replaced by a variable.
> Is this possible?

NO.

Although for 1.3 you might want to look at mod_macro.  httpd.conf within
itself is not a scripting language, and there has been massive push-back
against ever making it so.

If you want some really slick auto-templating, perhaps you would rather
generate your httpd.conf file, yourself, on the fly within your apachectl
script file.  Then you can use the power of perl, python, or simply awk
to accomplish exactly what you want.

Bill


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] how can I add SERVER_NAME to a filename

Posted by robert rottermann <ro...@redcor.ch>.
keith,
thank you very much for your answer.
I was a bit unclear. I know that I can name the files like this

CustomLog /var/log/apache2/projekte2.fh-aargau.ch/com_log combined

however I would like to have the "projekte2.fh-aargau.ch" part
replaced by a variable.
Is this possible?

somehow %{SERVER_NAME} must be known as I use it in a rewrite rule.

thanks
robert

httpd2@karsites.net wrote:
> Are you trying to add your own virtual server's name to your 
> apache log filename? If so, read the discusion on how to log 
> virtual hosts. You will find it on the manual home page under: 
>
> Users' Guide-> LogFiles->Virtual Hosts.
>
> You can then use the apache supplied perl script, 
> split-logfile to do the following: 
>
> >From the manual:
>
> split-logfile
>
> This perl script will take a combined Web server access log 
> file and break its contents into separate files. It assumes 
> that the first field of each line is the virtual host 
> identity (put there by "%v"), and that the logfiles should 
> be named that + ".log" in the current directory.
>
> The combined log file is read from stdin. Records read will 
> be appended to any existing log files.
>
> Or you can set up logging for each specified virtual host 
> like this:
>
> <VirtualHost 10.1.2.3>
>  DocumentRoot /www/docs/host.foo.com
>  ServerAdmin robert@redcor.net
>  ServerName projekte2.fh-aargau.ch
>  CustomLog /var/log/apache2/projekte2.fh-aargau.ch/com_log combined
>  ErrorLog  /var/log/apache2/projekte2.fh-aargau.ch/error_log
> </VirtualHost> 
>
> You will need to create the /projekte2.fh-aargau.ch/ 
> directory under /var/log/apache2. This will keep logs for 
> each virtual host seperate in their own sub-directory.
>
>
> HTH - Keith Roberts 
>
>
> On Mon, 2 Jan 2006, robert rottermann wrote:
>
>   
>> To: users@httpd.apache.org
>> From: robert rottermann <ro...@redcor.ch>
>> Subject: [users@httpd] how can I add SERVER_NAME to a filename
>>
>> Hi there,
>>
>> I would like to
>> use a construct like the following
>>
>> ServerAdmin robert@redcor.net
>> ServerName projekte2.fh-aargau.ch
>> CustomLog     /var/log/apache2/%{SERVER_NAME}.log combined
>> ErrorLog      /var/log/apache2/%{SERVER_NAME}.log
>>
>> However, the filename it creates is %{SERVER_NAME}.log instead of
>> projekte2.fh-aargau.ch.log
>>
>>
>> how can I achieve the desired result?
>>
>> thanks
>> robert
>>
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
>   


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] how can I add SERVER_NAME to a filename

Posted by ht...@karsites.net.
Are you trying to add your own virtual server's name to your 
apache log filename? If so, read the discusion on how to log 
virtual hosts. You will find it on the manual home page under: 

Users' Guide-> LogFiles->Virtual Hosts.

You can then use the apache supplied perl script, 
split-logfile to do the following: 

>From the manual:

split-logfile

This perl script will take a combined Web server access log 
file and break its contents into separate files. It assumes 
that the first field of each line is the virtual host 
identity (put there by "%v"), and that the logfiles should 
be named that + ".log" in the current directory.

The combined log file is read from stdin. Records read will 
be appended to any existing log files.

Or you can set up logging for each specified virtual host 
like this:

<VirtualHost 10.1.2.3>
 DocumentRoot /www/docs/host.foo.com
 ServerAdmin robert@redcor.net
 ServerName projekte2.fh-aargau.ch
 CustomLog /var/log/apache2/projekte2.fh-aargau.ch/com_log combined
 ErrorLog  /var/log/apache2/projekte2.fh-aargau.ch/error_log
</VirtualHost> 

You will need to create the /projekte2.fh-aargau.ch/ 
directory under /var/log/apache2. This will keep logs for 
each virtual host seperate in their own sub-directory.


HTH - Keith Roberts 


On Mon, 2 Jan 2006, robert rottermann wrote:

> To: users@httpd.apache.org
> From: robert rottermann <ro...@redcor.ch>
> Subject: [users@httpd] how can I add SERVER_NAME to a filename
> 
> Hi there,
> 
> I would like to
> use a construct like the following
> 
> ServerAdmin robert@redcor.net
> ServerName projekte2.fh-aargau.ch
> CustomLog     /var/log/apache2/%{SERVER_NAME}.log combined
> ErrorLog      /var/log/apache2/%{SERVER_NAME}.log
> 
> However, the filename it creates is %{SERVER_NAME}.log instead of
> projekte2.fh-aargau.ch.log
> 
> 
> how can I achieve the desired result?
> 
> thanks
> robert
> 
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org