From 88101fd8205c7c79769cefd1f78ee9fe238a29ed Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 14 Jan 2016 04:27:50 -0500 Subject: [PATCH] revert Daily Rolling Log File Bugs on daily rolling log file. Creation time not changed after roll --- shadowsocks-csharp/Controller/FileManager.cs | 20 --------- shadowsocks-csharp/Controller/Logging.cs | 47 +++----------------- 2 files changed, 5 insertions(+), 62 deletions(-) diff --git a/shadowsocks-csharp/Controller/FileManager.cs b/shadowsocks-csharp/Controller/FileManager.cs index 7c681f9c..f6edf147 100755 --- a/shadowsocks-csharp/Controller/FileManager.cs +++ b/shadowsocks-csharp/Controller/FileManager.cs @@ -43,25 +43,5 @@ namespace Shadowsocks.Controller destinationFile.Close(); } - public static void CompressFile(string fileName, byte[] content) - { - FileStream destinationFile = File.Create(fileName); - MemoryStream ms = new MemoryStream(content); - - // Because the compressed size of the file is unknown, - // we are using an arbitrary buffer size. - byte[] buffer = new byte[4096]; - int n; - - using (GZipStream output = new GZipStream(destinationFile, - CompressionMode.Compress, false)) - { - while ((n = ms.Read(buffer, 0, buffer.Length)) > 0) - { - output.Write(buffer, 0, n); - } - } - destinationFile.Close(); - } } } diff --git a/shadowsocks-csharp/Controller/Logging.cs b/shadowsocks-csharp/Controller/Logging.cs index aa06c24e..f2b170b0 100755 --- a/shadowsocks-csharp/Controller/Logging.cs +++ b/shadowsocks-csharp/Controller/Logging.cs @@ -18,20 +18,11 @@ namespace Shadowsocks.Controller { LogFilePath = Utils.GetTempPath("shadowsocks.log"); - if (!File.Exists(LogFilePath)) - using (File.Create(LogFilePath)) { } - LogFileCreationTime = File.GetCreationTime(LogFilePath); - - if ((DateTime.Now - LogFileCreationTime).Days >= 1) - RollLogFile(); - else - { - FileStream fs = new FileStream(LogFilePath, FileMode.Append); - StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs); - sw.AutoFlush = true; - Console.SetOut(sw); - Console.SetError(sw); - } + FileStream fs = new FileStream(LogFilePath, FileMode.Append); + StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(fs); + sw.AutoFlush = true; + Console.SetOut(sw); + Console.SetError(sw); return true; } @@ -42,36 +33,8 @@ namespace Shadowsocks.Controller } } - private static void RollLogFile() - { - Console.Out.Close(); - Console.Error.Close(); - - MemoryStream ms = new MemoryStream(); - StreamWriterWithTimestamp sw = new StreamWriterWithTimestamp(ms); - sw.AutoFlush = true; - Console.SetOut(sw); - Console.SetError(sw); - - byte[] logContents = File.ReadAllBytes(LogFilePath); - string datestr = DateTime.Now.AddDays(-1).ToString("yyyyMMdd"); - string filepath = Utils.GetTempPath($"shadowsocks.{datestr}.log.zip"); - FileManager.CompressFile(filepath, logContents); - - File.Delete(LogFilePath); - FileStream fs = new FileStream(LogFilePath, FileMode.CreateNew); - LogFileCreationTime = DateTime.Now; - ms.CopyTo(fs); - StreamWriterWithTimestamp sw2 = new StreamWriterWithTimestamp(fs); - sw2.AutoFlush = true; - Console.SetOut(sw2); - Console.SetError(sw2); - } - private static void WriteToLogFile(object o) { - if ((DateTime.Now - LogFileCreationTime).Days >= 1) - RollLogFile(); Console.WriteLine(o); }