Naming rotating log files specific name in Python
<p>I want to name rotating log files as I want.</p>

<p>For example, if I use RotatingFileHandler, It separates log file when it reaches to specific file size naming <code>log file name + extension numbering</code>, like below.</p>

<pre><code>filename.log      #first log file
filename.log.1    #rotating log file1
filename.log.2    #rotating log file2
</code></pre>

<p>However, I want log handler to name them every time it is created at.
For example.</p>

<pre><code>09-01-12-20.log    #first log file
09-01-12-43.log    #rotating log file1
09-01-15-00.log    #rotating log file2
</code></pre>

<p>How can I do this ?</p>

<p>Edit---------------------------</p>

<p>I am not asking how to create and name a file.</p>

<p>I want to facailate python <code>logging</code> package doing something like inheriting and overriding <code>logging</code> .</p>

<p>Check the following code and see if it helps. As far as I could understand from your question if your issue is in achieving the filename based on timestamp then this shall work for you.</p>

<pre><code>import datetime, time
# This return the epoch timestamp    
epochTime = time.time()
# We generate the timestamp 
# as per the need
timeStamp = datetime.datetime\
                    .fromtimestamp(epochTime)\
                    .strftime('%Y-%m-%d-%H-%M')
# Create a log file 
# use timeStamp as filename
fo = open(timeStamp+".log", "wb")
fo.write("Log data")
fo.close()
</code></pre>

python logging