Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace log line number on error in parsing w3c log file #45

Merged
merged 2 commits into from Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Stats.AzureCdnLogs.Common/CdnLogEntryParser.cs
Expand Up @@ -9,7 +9,7 @@ public static class CdnLogEntryParser
{
private static readonly DateTime _unixTimestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

public static CdnLogEntry ParseLogEntryFromLine(string line, Action<Exception> onErrorAction)
public static CdnLogEntry ParseLogEntryFromLine(int lineNumber, string line, Action<Exception, int> onErrorAction)
{
if (string.IsNullOrWhiteSpace(line))
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public static CdnLogEntry ParseLogEntryFromLine(string line, Action<Exception> o
}
else
{
onErrorAction.Invoke(e);
onErrorAction.Invoke(e, lineNumber);

return null;
}
Expand Down
18 changes: 14 additions & 4 deletions src/Stats.CollectAzureCdnLogs/Job.cs
Expand Up @@ -269,10 +269,13 @@ private void ProcessLogStream(Stream sourceStream, Stream targetStream, string f

try
{
var lineNumber = 0;
do
{
var rawLogLine = sourceStreamReader.ReadLine();
var logLine = GetParsedModifiedLogEntry(rawLogLine, fileName);
lineNumber++;

var logLine = GetParsedModifiedLogEntry(lineNumber, rawLogLine, fileName);
if (!string.IsNullOrEmpty(logLine))
{
targetStreamWriter.Write(logLine);
Expand All @@ -291,10 +294,17 @@ private void ProcessLogStream(Stream sourceStream, Stream targetStream, string f
}
}

private string GetParsedModifiedLogEntry(string rawLogEntry, string fileName)
private string GetParsedModifiedLogEntry(int lineNumber, string rawLogEntry, string fileName)
{
var parsedEntry = CdnLogEntryParser.ParseLogEntryFromLine(rawLogEntry,
e => _logger.LogError(LogEvents.FailedToParseLogFileEntry, e, "Failed to parse W3C log entry in {LogFileName}.", fileName));
var parsedEntry = CdnLogEntryParser.ParseLogEntryFromLine(
lineNumber,
rawLogEntry,
(e, line) => _logger.LogError(
LogEvents.FailedToParseLogFileEntry,
e,
"Failed to parse W3C log entry in {LogFileName} at line {LineNumber}.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a constant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it into resources in 2f9651f

fileName,
line));

if (parsedEntry == null)
{
Expand Down
14 changes: 12 additions & 2 deletions src/Stats.ImportAzureCdnStatistics/LogFileProcessor.cs
Expand Up @@ -210,13 +210,23 @@ private async Task<CdnStatistics> ParseLogEntries(ILeasedLogFile logFile, Packag

using (var logStreamReader = new StreamReader(logStream))
{
var lineNumber = 0;
do
{
var rawLogLine = logStreamReader.ReadLine();
if (rawLogLine != null)
{
var logEntry = CdnLogEntryParser.ParseLogEntryFromLine(rawLogLine,
e => _logger.LogError(LogEvents.FailedToParseLogFileEntry, e, "Failed to parse W3C log entry in {LogFileName}.", fileName));
lineNumber++;

var logEntry = CdnLogEntryParser.ParseLogEntryFromLine(
lineNumber,
rawLogLine,
(e, line) => _logger.LogError(
LogEvents.FailedToParseLogFileEntry,
e,
"Failed to parse W3C log entry in {LogFileName} at line {LineNumber}.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a constant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it into resources in 2f9651f

fileName,
line));

if (logEntry != null)
{
Expand Down