projectkudu/kudu — pull request #981 by paulbatum (2014-01-22 00:55:09+00:00)
Title: Implemented #967 - GET /logs/recent endpoint

This pull request adds a new API to kudu that can be used to retrieve the most recently written application log entries. For example:

GET /logs/recent?top=10

[
{
"timestamp": "2014-01-18T01:59:38+00:00",
"level": "Error",
"pid": 8416,
"message": "this is an error"
},
{
"timestamp": "2014-01-18T01:59:38+00:00",
"level": "Warning",
"pid": 8416,
"message": "this is a warning"
},
{
"timestamp": "2014-01-18T01:59:38+00:00",
"level": "Information",
"pid": 8416,
"message": "this is a log"
}
]

It assumes that the application logs are in the standard format used by ASP.NET applications running in Azure Web Sites. Any logs not in this format are ignored.

The general approach this API uses is to find the log files and then starting with the most recently written file, start reading log entries from the end of the file. If it reads log entries that are less recent than another file in the file system, it will switch to reading entries from that file and repeat the process.

I am still conducting performance testing but from a functional and design standpoint this change is ready for review.

Please note that I am using some third party code to read the log files in reverse order. The code is available under a permissive license and I have called it out in the notice.txt, but it would be great if someone can double check that I have handled this correctly.