citysir / log4go

Automatically exported from code.google.com/p/log4go
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Log file rotation not happening #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Version/System Details
======================
GoLang version 1.0.3
OS: Issue on Windows 7 and Debian linux
log4go version 3.0.1

Issue Description
=================
I have a fairly simple app that needs only one log file and I have defined my 
log4ggo configuration as follows:

<logging>
  <filter enabled="false">
    <tag>stdout</tag>
    <type>console</type>
    <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->
    <level>DEBUG</level>
  </filter>
  <filter enabled="true">
    <tag>AppLog</tag>
    <type>file</type>
    <level>DEBUG</level>
    <property name="format">[%D %T] [%L] (%S) %M</property>
    <property name="filename">app/log/main.log</property>
    <property name="rotate">false</property> <!-- true enables log rotation, otherwise append -->
    <property name="maxsize">5M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
    <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
    <property name="daily">false</property> <!-- Automatically rotates when a log message is written after midnight -->
  </filter>
</logging>

This creates the log file, it creates only one file and does not generate new 
files when the thresholds are met. You will see that I have rotate set to 
false. If I set 
    <property name="rotate">true</property> <!-- true enables log rotation, otherwise append -->
then the application when running writes every log line to a new file. 
Eventually it crashes as it has written so many log files it cannot generate a 
new unique log number this happens after main.log.999

What I would like is to keep a set of say 10 log files that are max size 5MB; 
in the same way the log4j works for Java.

Thanks for writing this library and making it available, on the whole it is an 
excellent package, thanks for you r efforts on it.

Original issue reported on code.google.com by ndav...@iparadigms.com on 7 Mar 2013 at 10:11

GoogleCodeExporter commented 9 years ago
Hi, 

I have to admit a little user error here. I was issuing:
l4g.LoadConfiguration()
in every func that I wanted logging and while this used the same file it was 
unnecessary.

I have changed my code base and can confirm that if rotate is set to true and 
the file size rotation is set then the behaviour is as expected.

One thing I would like is a way to set how many files to retain so that the log 
directory doesn't get clogged.

Thanks
Nathan

Original comment by ndav...@iparadigms.com on 13 Mar 2013 at 11:30