使用TimedRotatingFileHandler,如何使用与旋转相同的约定命名第一个日志文件?

时间:2016-05-03 19:20:26

标签: python logging

我使用undefined=&undefined=模块python 3.4来记录多天的性能。我想让它旋转,以便每天创建并写入名称中包含日期的新日志文件。 var data = [1, 2].map(function(item) { return { Id: item, Quantity: 1 } }); $.ajax({ url: "someUrl", type: "POST", dataType: "json", data: data }); 模块的logging处理程序做得很好。但是,假设我输入了一个日志文件名' FN.log'我得到了:

logging

等。

有没有办法让第一个文件也包含日期?我也考虑过可能会立即触发启动轮换,这应该可以解决问题,但我还不知道该怎么做。 谢谢!

PS:理想情况下,如果我碰巧杀死应用程序并在同一天重新启动它,它将继续写入与当天预先存在的应用程序相同的日志文件(例如,由轮换创建的文件) )。但是最后一位是可选的:如果它太难了,我每次运行程序时都可以创建一个新的日志目录。

1 个答案:

答案 0 :(得分:5)

这不是第一个文件 - 它是当前记录的文件。发生翻转时,文件TextBox将使用包含日期的名称重命名,并打开全新的Public Class Firmware Public Property ModelName As String Public Property PowerType As String Public Property Pic As String Public Property PartNumber As String Public Property Firmware As String Public Property Option1 As String End Class Public Class MainForm Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click Dim lines As String() = Nothing Try ' Read the file in one step lines = File.ReadAllLines("fwlist.txt") Catch ex As Exception Dim dialogResult As DialogResult = MessageBox.Show(Me, "File not found! Would you like to exit program?", "Error reading file", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) If dialogResult = DialogResult.Yes Then Me.Close() End If Exit Sub End Try Dim firmwares As List(Of Firmware) = New List(Of Firmware) For Each line As String In lines Dim rawData As String() = line.Split({","}, StringSplitOptions.None) ' Create Firmware object from each line Dim firmware As Firmware = New Firmware() With { .ModelName = rawData(0), .PowerType = rawData(1), .Pic = rawData(2), .PartNumber = rawData(3), .Firmware = rawData(4), .Option1 = rawData(5) } ' We store the read firmwares into a list firmwares.Add(firmware) Next ' Set the list as the data source of the combobox ' DisplayMember indicates which property will be shown in the combobox With cboModelNames .DataSource = firmwares .DisplayMember = "ModelName" End With End Sub Private Sub cboModelNames_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboModelNames.SelectedIndexChanged RefreshForm() End Sub Private Sub RefreshForm() ' Get the selected item as Firmware object Dim currentFirmware As Firmware = DirectCast(cboModelNames.SelectedItem, Firmware) ' Refresh all the textboxes with the information With currentFirmware txtPowerType.Text = .PowerType txtPic.Text = .Pic txtPartNumber.Text = .PartNumber txtFirmware.Text = .Firmware txtOption1.Text = .Option1 End With End Sub End Class 文件并用于后续日志,直到下一次翻转。< / p>