How can I keep only the last week of error logs?

Follow

There are a number of ways to do this.

The most common way to do this is to configure an action that runs on a regular schedule and invokes amps-action-do-remove-files to remove error logs that are older than 7 days.  For example, if the application logs to ${AMPS_MONITORING}/logs with file names that end in .log, you could configure an action like the following to run every night at 30 minutes after midnight (local time for the server):

<Action>
<On>
<Module>amps-action-on-schedule</Module>
<Options>
<Every>00:30</Every>
<Name>Daily event and error log cleanup</Name>
</Options>
</On>
<Do>
<Module>amps-action-do-remove-files</Module>
<Options>
<Age>7d</Age>
<Pattern>${AMPS_MONITORING}/logs/*.log</Pattern>
</Options>
</Do>
</Action>


Another approach is to use the log rotation action to rotate logs and create a file name specification that ensures that AMPS only keeps logs for the last 7 days.

Here's how to use these features together:

  • Create an action that rotates the log every day (typically, at midnight)
  • Specify a filename pattern for the log files that repeats every week

With these two configuration options in place, the effect is that AMPS will create a different log file each day, and reuse the same log file once every week.

The sample configuration below demonstrates how to do this: 

...

<Actions>
  <Action>
    <On>
     <Module>amps-action-on-schedule</Module>
<Options>
<Every>00:00</Every>
</Options>
</On>
<Do>
<Module>amps-action-do-rotate-logs</Module>
<Options>
<Age>10s</Age>
</Options>
</Do>
</Action>
</Actions>
<Logging> <Target> <Protocol>file</Protocol> <!-- Log files uses the day of the week in the format, so: AMPS-InstanceName-Friday.log --> <FileName>./logs-dest/AMPS-InstanceName-%A.log</FileName> <Level>info</Level> </Target> </Logging>

...  

Notice that the configuration above doesn't set a RotationThreshold for the log. Instead, the log is allowed to grow until the Action rotates it once a day.

 

keywords: log rotation, log size, AMPS maintenance

Have more questions? Submit a request

Comments

Powered by Zendesk