You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Patrick McCambridge <mc...@fdny.nyc.gov> on 2010/11/05 22:04:49 UTC

[users@httpd] Rotating logs

Because I am not a Unix person or web developer, I am struggling with the exercise to rotate my logs in Apache (I am running 2.2).
 
When I add the following command to my httpd.conf file, it creates a file called access_log.old (in the time interval I designate), but Apache still continues to write to the original log.
 
Here is the command I am using:
CustomLog "|apache22/bin/rotatelogs /apache22/logs/archive_log 300" combine
 
How do I tweak this to ensure the new log that is created becomes the primary log, until it's time to replace it, and them it becomes archived?
 
Thank you in advance.
Patrick

Confidentiality Notice:
This message may contain information that is 
confidential or privileged.

If you are not the intended recipient, 
Please advise the sender immediately and delete this message.

Re: [users@httpd] Rotating logs

Posted by Nerius Landys <nl...@gmail.com>.
There are other ways to rotate Apache logs, too.  For example, on my FreeBSD
systems, there is something called newsyslog present at the operating system
level.  There is a file named /etc/newsyslog.conf that has the following
lines on my system (I edited the file and added these lines):

# logfilename          [owner:group]    mode count size when  flags
[/pid_file] [sig_num]
/var/log/httpd-access.log               644  10    1000 *     J
/var/run/httpd.pid    30
/var/log/httpd-error.log                644  10    1000 *     J
/var/run/httpd.pid    30

The signal 30 on FreeBSD is SIGUSR1.  SIGUSR1 is what you send to Apache to
close the current log and start a new one, or something like that.  SIGUSR1
is probably a different number on your Linux system.  Anyhow, the entries
above in newsyslog on my system make everything work perfectly.  Logs are
rotated, archived, and removed after there are too many archived logs.

I prefer rotating logs with newsyslog.

RE: [users@httpd] Rotating logs

Posted by "Bennett, Tony" <Be...@con-way.com>.
It appears you are running on a Windows System.
.My environment is AIX (i.e. Unix).. .so, the manner in which you specify a full path 
of rotatelogs or the apache_access_log differs (i.e. Unix has no 'concept' of a drive. e.g.:  V:\)

A little research indicacates you should be able to specify the drive-letter 
. just be sure to use forward slashes in the path... additionally you may have
to append ".exe" onto rotatelogs:

    TransferLog "| V:/Apache22/bin/rotatelogs.exe -l -f V:/Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400"

That said, the documentation specifies that using TransferLog:

    This directive has exactly the same arguments and effect as the CustomLog directive, 
    with the exception that it does not allow the log format to be specified explicitly 
    or for conditional logging of requests. Instead, the log format is determined by the 
    most recently specified LogFormat directive which does not define a nickname. Common 
    Log Format is used if no other format has been specified.

    Example
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
        TransferLog logs/access_log 

Notice that in the example, the LogFormat for the ApacheAccessLog is immediately before the TransferLog directive..

If you still have problems, You might also read over this link on the use of 
"pipe":   http://httpd.apache.org/docs/2.2/logs.html#piped 

-tony

From: Patrick McCambridge [mailto:mccambp@fdny.nyc.gov] 
Sent: Friday, November 12, 2010 11:11 AM
To: users@httpd.apache.org
Subject: RE: [users@httpd] Rotating logs

Hi Tony, the answers to your first questions are yes and yes.  I am running Apache 2.2.16
 
Here is my full path to rotatelogs:
V:\Apache22\bin
 
Here is my full path to logs folder:
V:\Apache22\logs
 
Here are my current logs in logs folder:
access.log
access_comb.log
error.log
install.log
 
Here is portion of the config file, your recommended line is the last line:
 
#
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog "logs/access.log" common
 
    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog "logs/access_comb.log" combined
    TransferLog "| /Apache22/bin/rotatelogs -l -f /Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400"


>>> "Bennett, Tony" <Be...@con-way.com> 11/12/2010 10:40 AM >>>
Patrick

Is "/Apache22/bin/rotatelogs" to full path to "rotatelogs" ...???
Is "/Apache22/logs" the full path to Apache's "logs" directory ...???

What version of Apache are you using????

Please show the context in your httpd.conf in which you specified rotatelog.

The example I provided was lifted from our httpd.conf (we are running V 2.2.10 in production).
If you need a "greater" context, I can provide it for you.

As an FYI, here is a link to the Apache2.2 documentation of TransferLog (which is what we use):
    http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#transferlog


-tony

From: Patrick McCambridge [mailto:mccambp@fdny.nyc.gov] 
Sent: Friday, November 12, 2010 7:05 AM
To: users@httpd.apache.org
Subject: RE: [users@httpd] Rotating logs

Hi Tony, finally had a chance to test this.  All I did was change the directory to reflect my actual directory, and I am getting this message (did some tweaking but can't get around this):

piped log program ' /Apache22/bin/rotatelogs -l -f /Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400' failed unexpectedly
Could not open log file '/Apache22/logs/apache_access_log.11-12-10-12:00:00' (The filename, directory name, or volume label syntax is incorrect.  )

>>> "Bennett, Tony" <Be...@con-way.com> 11/5/2010 6:17 PM >>>
TransferLog "| /usr/local/apache/bin/rotatelogs -l -f /var/adm/syslog/apache_access_log.%m-%d-%y-%I:%M:%S 86400"



Confidentiality Notice:
This message may contain information that is
confidential or privileged.

If you are not the intended recipient,
Please advise the sender immediately and delete this message. 

---------------------------------------------------------------------
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



Confidentiality Notice:
This message may contain information that is
confidential or privileged.

If you are not the intended recipient,
Please advise the sender immediately and delete this message. 

---------------------------------------------------------------------
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] Rotating logs

Posted by Joost de Heer <jo...@sanguis.xs4all.nl>.
On 11/12/2010 08:11 PM, Patrick McCambridge wrote:
> Hi Tony, the answers to your first questions are yes and yes.  I am running
> Apache 2.2.16
> Here is my full path to rotatelogs:
> V:\Apache22\bin
> Here is my full path to logs folder:
> V:\Apache22\logs

> TransferLog "| /Apache22/bin/rotatelogs -l -f
> /Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400"

You're running Apache on Windows, but you're using Unix paths here. Change this to

TransferLog "| V:/Apache22/bin/rotatelogs.exe -l -f 
V:/Apache22/logs/access-%m-%d-%y-%I-%M-%S.log 86400"

(please note that : is an illegal character in a Windows filename)

Joost

---------------------------------------------------------------------
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] Rotating logs

Posted by Patrick McCambridge <mc...@fdny.nyc.gov>.
Hi Tony, the answers to your first questions are yes and yes.  I am running Apache 2.2.16
 
Here is my full path to rotatelogs:
V:\Apache22\bin
 
Here is my full path to logs folder:
V:\Apache22\logs
 
Here are my current logs in logs folder:
access.log
access_comb.log
error.log
install.log
 
Here is portion of the config file, your recommended line is the last line:
 
#
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog "logs/access.log" common
 
    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog "logs/access_comb.log" combined
    TransferLog "| /Apache22/bin/rotatelogs -l -f /Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400"


>>> "Bennett, Tony" <Be...@con-way.com> 11/12/2010 10:40 AM >>>
Patrick

Is "/Apache22/bin/rotatelogs" to full path to "rotatelogs" ...???
Is "/Apache22/logs" the full path to Apache's "logs" directory ..???

What version of Apache are you using????

Please show the context in your httpd.conf in which you specified rotatelog.

The example I provided was lifted from our httpd.conf (we are running V 22.10 in production).
If you need a "greater" context, I can provide it for you.

As an FYI, here is a link to the Apache2.2 documentation of TransferLog (which is what we use):
    http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#transferlog


-tony

From: Patrick McCambridge [mailto:mccambp@fdny.nyc.gov] 
Sent: Friday, November 12, 2010 7:05 AM
To: users@httpd.apache.org
Subject: RE: [users@httpd] Rotating logs

Hi Tony, finally had a chance to test this.  All I did was change the directory to reflect my actual directory, and I am getting this message (did some tweaking but can't get around this):

piped log program ' /Apache22/bin/rotatelogs -l -f /Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400' failed unexpectedly
Could not open log file '/Apache22/logs/apache_access_log.11-12-10-12:00:00' (The filename, directory name, or volume label syntax is incorrect.  )

>>> "Bennett, Tony" <Be...@con-way.com> 11/5/2010 6:17 PM >>>
TransferLog "| /usr/local/apache/bin/rotatelogs -l -f /var/adm/syslog/apache_access_log.%m-%d-%y-%I:%M:%S 86400"



Confidentiality Notice:
This message may contain information that is
confidential or privileged.

If you are not the intended recipient,
Please advise the sender immediately and delete this message. 

---------------------------------------------------------------------
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


Confidentiality Notice:
This message may contain information that is 
confidential or privileged.

If you are not the intended recipient, 
Please advise the sender immediately and delete this message.

RE: [users@httpd] Rotating logs

Posted by "Bennett, Tony" <Be...@con-way.com>.
Patrick

Is "/Apache22/bin/rotatelogs" to full path to "rotatelogs" ...???
Is "/Apache22/logs" the full path to Apache's "logs" directory ...???

What version of Apache are you using????

Please show the context in your httpd.conf in which you specified rotatelog.

The example I provided was lifted from our httpd.conf (we are running V 2.2.10 in production).
If you need a "greater" context, I can provide it for you.

As an FYI, here is a link to the Apache2.2 documentation of TransferLog (which is what we use):
    http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#transferlog


-tony

From: Patrick McCambridge [mailto:mccambp@fdny.nyc.gov] 
Sent: Friday, November 12, 2010 7:05 AM
To: users@httpd.apache.org
Subject: RE: [users@httpd] Rotating logs

Hi Tony, finally had a chance to test this.  All I did was change the directory to reflect my actual directory, and I am getting this message (did some tweaking but can't get around this):
 
piped log program ' /Apache22/bin/rotatelogs -l -f /Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400' failed unexpectedly
Could not open log file '/Apache22/logs/apache_access_log.11-12-10-12:00:00' (The filename, directory name, or volume label syntax is incorrect.  )

>>> "Bennett, Tony" <Be...@con-way.com> 11/5/2010 6:17 PM >>>
TransferLog "| /usr/local/apache/bin/rotatelogs -l -f /var/adm/syslog/apache_access_log.%m-%d-%y-%I:%M:%S 86400"



Confidentiality Notice:
This message may contain information that is
confidential or privileged.

If you are not the intended recipient,
Please advise the sender immediately and delete this message. 

---------------------------------------------------------------------
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] Rotating logs

Posted by Patrick McCambridge <mc...@fdny.nyc.gov>.
Hi Tony, finally had a chance to test this.  All I did was change the directory to reflect my actual directory, and I am getting this message (did some tweaking but can't get around this):
 
piped log program ' /Apache22/bin/rotatelogs -l -f /Apache22/logs/apache_access_log.%m-%d-%y-%I:%M:%S 86400' failed unexpectedly
Could not open log file '/Apache22/logs/apache_access_log.11-12-10-12:00:00' (The filename, directory name, or volume label syntax is incorrect.  )

>>> "Bennett, Tony" <Be...@con-way.com> 11/5/2010 6:17 PM >>>
TransferLog "| /usr/local/apache/bin/rotatelogs -l -f /var/adm/syslog/apache_access_log.%m-%d-%y-%I:%M:%S 86400"

Confidentiality Notice:
This message may contain information that is 
confidential or privileged.

If you are not the intended recipient, 
Please advise the sender immediately and delete this message.

RE: [users@httpd] Rotating logs

Posted by "Bennett, Tony" <Be...@con-way.com>.
Patrick,

For me, examples always help the most.
Here's what we do...

    TransferLog "| /usr/local/apache/bin/rotatelogs -l -f /var/adm/syslog/apache_access_log.%m-%d-%y-%I:%M:%S 86400"

This way, our apache_access_log filename is appended with the month-day-year-hour-minute-second... 
...and its rotated every 86400 seconds (once a day).  
You'll note we specify "-l", which means all processing is done in local time.

Here's an example of one of our apache_access_log filenames:

	/var/adm/syslog/apache_access_log.11-05-10-12:00:00 

hope this helps.

-tony

From: Patrick McCambridge [mailto:mccambp@fdny.nyc.gov] 
Sent: Friday, November 05, 2010 2:05 PM
To: users@httpd.apache.org
Subject: [users@httpd] Rotating logs

Because I am not a Unix person or web developer, I am struggling with the exercise to rotate my logs in Apache (I am running 2.2).
 
When I add the following command to my httpd.conf file, it creates a file called access_log.old (in the time interval I designate), but Apache still continues to write to the original log.
 
Here is the command I am using:
CustomLog "|apache22/bin/rotatelogs /apache22/logs/archive_log 300" combine
 
How do I tweak this to ensure the new log that is created becomes the primary log, until it's time to replace it, and them it becomes archived?
 
Thank you in advance.
Patrick



Confidentiality Notice:
This message may contain information that is
confidential or privileged.

If you are not the intended recipient,
Please advise the sender immediately and delete this message. 

---------------------------------------------------------------------
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