Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LogExpert.Tests/ColumnizerPickerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void FindReplacementForAutoColumnizer_ValidTextFile_ReturnCorrectColumniz
string fileName, Type columnizerType)
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions());
LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
reader.ReadFiles();

Mock<ILogLineColumnizer> autoColumnizer = new Mock<ILogLineColumnizer>();
Expand Down
2 changes: 1 addition & 1 deletion src/LogExpert.Tests/JsonColumnizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void GetColumnNames_HappyFile_ColumnNameMatches(string fileName, string e
{
var jsonColumnizer = new JsonColumnizer.JsonColumnizer();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions());
LogfileReader reader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
reader.ReadFiles();

ILogLine line = reader.GetLogLineWithWait(0);
Expand Down
2 changes: 1 addition & 1 deletion src/LogExpert.Tests/JsonCompactColumnizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void GetPriority_HappyFile_PriorityMatches(string fileName, Priority prio
{
var jsonCompactColumnizer = new JsonColumnizer.JsonCompactColumnizer();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions());
LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
logFileReader.ReadFiles();
List<ILogLine> loglines = new List<ILogLine>
{
Expand Down
2 changes: 1 addition & 1 deletion src/LogExpert.Tests/SquareBracketColumnizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void GetPriority_HappyFile_ColumnCountMatches(string fileName, int count)
SquareBracketColumnizer squareBracketColumnizer = new SquareBracketColumnizer();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);

LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions());
LogfileReader logFileReader = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultiFileOptions());
logFileReader.ReadFiles();
List<ILogLine> loglines = new List<ILogLine>
{
Expand Down
6 changes: 3 additions & 3 deletions src/LogExpert/Classes/Log/LogfileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LogfileReader : IAutoLogLineColumnizerCallback
private readonly int _MAX_LINES_PER_BUFFER = 100;

private readonly object _monitor = new object();
private readonly MultifileOptions _multiFileOptions;
private readonly MultiFileOptions _multiFileOptions;

private IList<LogBuffer> _bufferList;
private ReaderWriterLock _bufferListLock;
Expand Down Expand Up @@ -50,7 +50,7 @@ public class LogfileReader : IAutoLogLineColumnizerCallback

#region cTor

public LogfileReader(string fileName, EncodingOptions encodingOptions, bool multiFile, int bufferCount, int linesPerBuffer, MultifileOptions multiFileOptions)
public LogfileReader(string fileName, EncodingOptions encodingOptions, bool multiFile, int bufferCount, int linesPerBuffer, MultiFileOptions multiFileOptions)
{
if (fileName == null)
{
Expand Down Expand Up @@ -88,7 +88,7 @@ public LogfileReader(string fileName, EncodingOptions encodingOptions, bool mult
StartGCThread();
}

public LogfileReader(string[] fileNames, EncodingOptions encodingOptions, int bufferCount, int linesPerBuffer, MultifileOptions multiFileOptions)
public LogfileReader(string[] fileNames, EncodingOptions encodingOptions, int bufferCount, int linesPerBuffer, MultiFileOptions multiFileOptions)
{
if (fileNames == null || fileNames.Length < 1)
{
Expand Down
27 changes: 13 additions & 14 deletions src/LogExpert/Classes/Log/PositionAwareStreamReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ protected PositionAwareStreamReaderBase(Stream stream, EncodingOptions encodingO
{
_stream = new BufferedStream(stream);

Encoding detectedEncoding;
_preambleLength = DetectPreambleLengthAndEncoding(out detectedEncoding);
_preambleLength = DetectPreambleLengthAndEncoding(out Encoding detectedEncoding);

Encoding usedEncoding = getUsedEncoding(encodingOptions, detectedEncoding);
_posIncPrecomputed = getPosIncPrecomputed(usedEncoding);
Expand All @@ -48,16 +47,16 @@ protected PositionAwareStreamReaderBase(Stream stream, EncodingOptions encodingO
/// </summary>
public sealed override long Position
{
get { return _position; }
get => _position;
set
{
/*
* 1: Irgendwann mal auskommentiert (+Encoding.GetPreamble().Length)
* 2: Stand bei 1.1 3207
* 3: Stand nach Fehlermeldung von Piet wegen Unicode-Bugs.
* Keihne Ahnung, ob das jetzt endgültig OK ist.
* 4: 27.07.09: Preamble-Length wird jetzt im CT ermittelt, da Encoding.GetPreamble().Length
* immer eine fixe Länge liefert (unabhängig vom echtem Dateiinhalt)
* 1: Sometime commented (+Encoding.GetPreamble().Length)
* 2: Date 1.1 3207
* 3: Error Message from Piet because of Unicode-Bugs.
* No Idea, if this is OK.
* 4: 27.07.09: Preamble-Length is now calculated in CT, because Encoding.GetPreamble().Length
* always delivers a fixed length (does not mater what kind of data)
*/
_position = value; // +Encoding.GetPreamble().Length; // 1
//stream.Seek(pos, SeekOrigin.Begin); // 2
Expand Down Expand Up @@ -144,11 +143,11 @@ protected void MovePosition(int offset)
private int DetectPreambleLengthAndEncoding(out Encoding detectedEncoding)
{
/*
UTF-8: EF BB BF
UTF-16-Big-Endian-Bytereihenfolge: FE FF
UTF-16-Little-Endian-Bytereihenfolge: FF FE
UTF-32-Big-Endian-Bytereihenfolge: 00 00 FE FF
UTF-32-Little-Endian-Bytereihenfolge: FF FE 00 00
UTF-8: EF BB BF
UTF-16-Big-Endian-Byteorder: FE FF
UTF-16-Little-Endian-Byteorder: FF FE
UTF-32-Big-Endian-Byteorder: 00 00 FE FF
UTF-32-Little-Endian-Byteorder: FF FE 00 00
*/

byte[] readPreamble = new byte[4];
Expand Down
98 changes: 46 additions & 52 deletions src/LogExpert/Classes/Log/RolloverFilenameBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public class RolloverFilenameBuilder
{
#region Fields

private string condContent;
private Group condGroup;
private string currentFileName;
private string _condContent;
private Group _condGroup;
private string _currentFileName;

private Group dateGroup;
private Group _dateGroup;

//private Regex regexCond;
private DateTime dateTime;
private DateTime _dateTime;

//private DateTimeFormatInfo dateFormat;
private string dateTimeFormat = null;
private string _dateTimeFormat;

private bool hideZeroIndex;
private Group indexGroup;
private Regex regex;
private bool _hideZeroIndex;
private Group _indexGroup;
private Regex _regex;

#endregion

Expand All @@ -60,76 +60,70 @@ public RolloverFilenameBuilder(string formatString)

public int Index { get; set; }

public bool IsDatePattern
{
get { return this.dateGroup != null && this.dateGroup.Success; }
}
public bool IsDatePattern => _dateGroup != null && _dateGroup.Success;

public bool IsIndexPattern
{
get { return this.indexGroup != null && this.indexGroup.Success; }
}
public bool IsIndexPattern => _indexGroup != null && _indexGroup.Success;

#endregion

#region Public methods

public void SetFileName(string fileName)
{
this.currentFileName = fileName;
Match match = this.regex.Match(fileName);
_currentFileName = fileName;
Match match = _regex.Match(fileName);
if (match.Success)
{
this.dateGroup = match.Groups["date"];
if (this.dateGroup.Success)
_dateGroup = match.Groups["date"];
if (_dateGroup.Success)
{
string date = fileName.Substring(dateGroup.Index, dateGroup.Length);
if (DateTime.TryParseExact(date, this.dateTimeFormat, DateTimeFormatInfo.InvariantInfo,
string date = fileName.Substring(_dateGroup.Index, _dateGroup.Length);
if (DateTime.TryParseExact(date, _dateTimeFormat, DateTimeFormatInfo.InvariantInfo,
DateTimeStyles.None,
out this.dateTime))
out _dateTime))
{
}
}
this.indexGroup = match.Groups["index"];
if (this.indexGroup.Success)
_indexGroup = match.Groups["index"];
if (_indexGroup.Success)
{
this.Index = this.indexGroup.Value.Length > 0 ? int.Parse(indexGroup.Value) : 0;
Index = _indexGroup.Value.Length > 0 ? int.Parse(_indexGroup.Value) : 0;
}
this.condGroup = match.Groups["cond"];
_condGroup = match.Groups["cond"];
}
}

public void IncrementDate()
{
this.dateTime = dateTime.AddDays(1);
_dateTime = _dateTime.AddDays(1);
}

public void DecrementDate()
{
this.dateTime = dateTime.AddDays(-1);
_dateTime = _dateTime.AddDays(-1);
}


public string BuildFileName()
{
string fileName = this.currentFileName;
if (this.dateGroup != null && this.dateGroup.Success)
string fileName = _currentFileName;
if (_dateGroup != null && _dateGroup.Success)
{
string newDate = dateTime.ToString(this.dateTimeFormat, DateTimeFormatInfo.InvariantInfo);
fileName = fileName.Remove(this.dateGroup.Index, this.dateGroup.Length);
fileName = fileName.Insert(this.dateGroup.Index, newDate);
string newDate = _dateTime.ToString(_dateTimeFormat, DateTimeFormatInfo.InvariantInfo);
fileName = fileName.Remove(_dateGroup.Index, _dateGroup.Length);
fileName = fileName.Insert(_dateGroup.Index, newDate);
}
if (this.indexGroup != null && this.indexGroup.Success)
if (_indexGroup != null && _indexGroup.Success)
{
fileName = fileName.Remove(this.indexGroup.Index, this.indexGroup.Length);
fileName = fileName.Remove(_indexGroup.Index, _indexGroup.Length);
string fileNameBak = fileName;
if (!this.hideZeroIndex || this.Index > 0)
if (!_hideZeroIndex || Index > 0)
{
string format = "D" + this.indexGroup.Length;
fileName = fileName.Insert(this.indexGroup.Index, this.Index.ToString(format));
if (this.hideZeroIndex && this.condContent != null)
string format = "D" + _indexGroup.Length;
fileName = fileName.Insert(_indexGroup.Index, Index.ToString(format));
if (_hideZeroIndex && _condContent != null)
{
fileName = fileName.Insert(this.indexGroup.Index, this.condContent);
fileName = fileName.Insert(_indexGroup.Index, _condContent);
}
}
}
Expand All @@ -144,24 +138,24 @@ public string BuildFileName()

private void ParseFormatString(string formatString)
{
string fmt = escapeNonvarRegions(formatString);
string fmt = EscapeNonvarRegions(formatString);
int datePos = formatString.IndexOf("$D(");
if (datePos != -1)
{
int endPos = formatString.IndexOf(')', datePos);
if (endPos != -1)
{
this.dateTimeFormat = formatString.Substring(datePos + 3, endPos - datePos - 3);
this.dateTimeFormat = this.dateTimeFormat.ToUpper();
this.dateTimeFormat = this.dateTimeFormat.Replace('D', 'd').Replace('Y', 'y');
_dateTimeFormat = formatString.Substring(datePos + 3, endPos - datePos - 3);
_dateTimeFormat = _dateTimeFormat.ToUpper();
_dateTimeFormat = _dateTimeFormat.Replace('D', 'd').Replace('Y', 'y');

string dtf = this.dateTimeFormat;
string dtf = _dateTimeFormat;
dtf = dtf.ToUpper();
dtf = dtf.Replace("D", "\\d");
dtf = dtf.Replace("Y", "\\d");
dtf = dtf.Replace("M", "\\d");
fmt = fmt.Remove(datePos, 2); // remove $D
fmt = fmt.Remove(datePos + 1, this.dateTimeFormat.Length); // replace with regex version of format
fmt = fmt.Remove(datePos + 1, _dateTimeFormat.Length); // replace with regex version of format
fmt = fmt.Insert(datePos + 1, dtf);
fmt = fmt.Insert(datePos + 1, "?'date'"); // name the regex group
}
Expand All @@ -173,20 +167,20 @@ private void ParseFormatString(string formatString)
int endPos = fmt.IndexOf(')', condPos);
if (endPos != -1)
{
this.condContent = fmt.Substring(condPos + 3, endPos - condPos - 3);
_condContent = fmt.Substring(condPos + 3, endPos - condPos - 3);
fmt = fmt.Remove(condPos + 2, endPos - condPos - 1);
}
}

fmt = fmt.Replace("*", ".*");
this.hideZeroIndex = fmt.Contains("$J");
_hideZeroIndex = fmt.Contains("$J");
fmt = fmt.Replace("$I", "(?'index'[\\d]+)");
fmt = fmt.Replace("$J", "(?'index'[\\d]*)");

this.regex = new Regex(fmt);
_regex = new Regex(fmt);
}

private string escapeNonvarRegions(string formatString)
private string EscapeNonvarRegions(string formatString)
{
string fmt = formatString.Replace('*', '\xFFFD');
StringBuilder result = new StringBuilder();
Expand Down
48 changes: 23 additions & 25 deletions src/LogExpert/Classes/Log/RolloverFilenameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class RolloverFilenameHandler
{
#region Fields

private readonly RolloverFilenameBuilder filenameBuilder;
private readonly ILogFileInfo logFileInfo;
private readonly MultifileOptions options;
private readonly RolloverFilenameBuilder _filenameBuilder;
private readonly ILogFileInfo _logFileInfo;
private readonly MultiFileOptions _options;

#endregion

Expand All @@ -27,14 +27,14 @@ public class RolloverFilenameHandler
/// <summary>
/// Constructor.
/// </summary>
/// <param name="filePath">The complete path of the logfile</param>
/// <param name="logFileInfo">The complete path of the logfile</param>
/// <param name="options">Multifile option (e.g. format pattern)</param>
public RolloverFilenameHandler(ILogFileInfo logFileInfo, MultifileOptions options)
public RolloverFilenameHandler(ILogFileInfo logFileInfo, MultiFileOptions options)
{
this.options = options;
this.logFileInfo = logFileInfo;
this.filenameBuilder = new RolloverFilenameBuilder(this.options.FormatPattern);
this.filenameBuilder.SetFileName(logFileInfo.FileName);
_options = options;
_logFileInfo = logFileInfo;
_filenameBuilder = new RolloverFilenameBuilder(_options.FormatPattern);
_filenameBuilder.SetFileName(logFileInfo.FileName);
}

#endregion
Expand All @@ -51,19 +51,19 @@ public RolloverFilenameHandler(ILogFileInfo logFileInfo, MultifileOptions option
public LinkedList<string> GetNameList()
{
LinkedList<string> fileList = new LinkedList<string>();
string fileName = filenameBuilder.BuildFileName();
string filePath = this.logFileInfo.DirectoryName + this.logFileInfo.DirectorySeparatorChar + fileName;
string fileName = _filenameBuilder.BuildFileName();
string filePath = _logFileInfo.DirectoryName + _logFileInfo.DirectorySeparatorChar + fileName;
fileList.AddFirst(filePath);
bool found = true;
while (found)
{
found = false;
// increment index and check if file exists
if (this.filenameBuilder.IsIndexPattern)
if (_filenameBuilder.IsIndexPattern)
{
this.filenameBuilder.Index = this.filenameBuilder.Index + 1;
fileName = filenameBuilder.BuildFileName();
filePath = this.logFileInfo.DirectoryName + this.logFileInfo.DirectorySeparatorChar + fileName;
_filenameBuilder.Index += 1;
fileName = _filenameBuilder.BuildFileName();
filePath = _logFileInfo.DirectoryName + _logFileInfo.DirectorySeparatorChar + fileName;
if (FileExists(filePath))
{
fileList.AddFirst(filePath);
Expand All @@ -72,25 +72,23 @@ public LinkedList<string> GetNameList()
}
}
// if file with index isn't found or no index is in format pattern, decrement the current date
if (this.filenameBuilder.IsDatePattern)
if (_filenameBuilder.IsDatePattern)
{
int tryCounter = 0;
this.filenameBuilder.Index = 0;
while (tryCounter < this.options.MaxDayTry)
_filenameBuilder.Index = 0;
while (tryCounter < _options.MaxDayTry)
{
this.filenameBuilder.DecrementDate();
fileName = filenameBuilder.BuildFileName();
filePath = this.logFileInfo.DirectoryName + this.logFileInfo.DirectorySeparatorChar + fileName;
_filenameBuilder.DecrementDate();
fileName = _filenameBuilder.BuildFileName();
filePath = _logFileInfo.DirectoryName + _logFileInfo.DirectorySeparatorChar + fileName;
if (FileExists(filePath))
{
fileList.AddFirst(filePath);
found = true;
break;
}
else
{
tryCounter++;
}

tryCounter++;
}
}
}
Expand Down
Loading