Skip to content

Commit

Permalink
Add a silent try catch while printing previous log tail (Azure-App-Se…
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchitmehta authored Aug 19, 2019
1 parent ee1015b commit 1412828
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions Kudu.Services/Diagnostics/LogStreamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task ProcessRequest(HttpContext context)

FileSystemHelpers.EnsureDirectory(mountedLogFilesDir);

if (shouldMonitiorMountedLogsPath(mountedLogFilesDir))
if (ShouldMonitiorMountedLogsPath(mountedLogFilesDir))
{
path = mountedLogFilesDir;
}
Expand All @@ -127,33 +127,43 @@ public async Task ProcessRequest(HttpContext context)
{
NotifyClientWithLineBreak("Starting Log Tail -n 10 of existing logs ----", context);

foreach (string log in _logFiles.Keys)
try
{
var reader = new StreamReader(log, Encoding.ASCII);

var vfsPath = GetFileVfsPath(log);

var printLine = log + " " + (!string.IsNullOrEmpty(vfsPath) ? " (" + vfsPath + ")" : "");
foreach (string log in _logFiles.Keys)
{

var reader = new StreamReader(log, Encoding.ASCII);

NotifyClientWithLineBreak(String.Format(
CultureInfo.CurrentCulture,
printLine,
DateTime.UtcNow.ToString("s"),
System.Environment.NewLine),context);
var vfsPath = GetFileVfsPath(log);

foreach (string logLine in Tail(reader, 10))
{
await context.Response.WriteAsync(logLine);
var printLine = log + " " + (!string.IsNullOrEmpty(vfsPath) ? " (" + vfsPath + ")" : "");

NotifyClientWithLineBreak(String.Format(
CultureInfo.CurrentCulture,
printLine,
DateTime.UtcNow.ToString("s"),
System.Environment.NewLine), context);

foreach (string logLine in Tail(reader, 10))
{
await context.Response.WriteAsync(logLine);
await context.Response.WriteAsync(System.Environment.NewLine);
}
await context.Response.WriteAsync(System.Environment.NewLine);
}
await context.Response.WriteAsync(System.Environment.NewLine);
}
catch (Exception)
{
// best effort to get tail logs
}

NotifyClientWithLineBreak("Ending Log Tail of existing logs ---", context);
}
else
{
_tracer.TraceError("LogStream: No pervious logfiles");
Console.WriteLine("LogStream: No pervious logfiles");
}

NotifyClientWithLineBreak("Starting Live Log Stream ---", context);
Expand Down Expand Up @@ -239,7 +249,7 @@ private static Task WriteInitialMessage(HttpContext context)
/// or the mounted fs logs dir, if kudu
/// </summary>
/// <returns></returns>
private static bool shouldMonitiorMountedLogsPath(string mountedDirPath)
private static bool ShouldMonitiorMountedLogsPath(string mountedDirPath)
{
int count = 0;
string dateToday = DateTime.Now.ToString("yyyy_MM_dd");
Expand Down

0 comments on commit 1412828

Please sign in to comment.