Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9c060cd0d | ||
|
|
acf3f8c0fe | ||
|
|
ea09bd6b19 | ||
|
|
2bfa977d99 | ||
|
|
ddbfa25f8e |
@@ -17,6 +17,9 @@ namespace CloudWatchLogDownloader.Models
|
||||
[ValueOption(2)]
|
||||
public string OutputFilePath { get; set; }
|
||||
|
||||
[Option('l', "liveStream", HelpText="Keep pulling logs until Ctrl+C is applied")]
|
||||
public bool LiveStream { get; set; }
|
||||
|
||||
[ParserState]
|
||||
public IParserState ParserState { get; set; }
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace CloudWatchLogDownloader
|
||||
client = new AmazonCloudWatchLogsClient();
|
||||
var logGroup = GetLogGroup(opt.LogGroup);
|
||||
var logStream = GetLogStream(logGroup, opt.LogStream);
|
||||
WriteLogToFile(logGroup, logStream, opt.OutputFilePath);
|
||||
WriteLogToFile(logGroup, logStream, opt.LiveStream, opt.OutputFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace CloudWatchLogDownloader
|
||||
allStreams = allStreams.Where(x => x.LogStreamName.StartsWith(logStream)).ToList();
|
||||
}
|
||||
|
||||
allStreams = allStreams.OrderBy(x => x.CreationTime).ToList();
|
||||
allStreams = allStreams.OrderByDescending(x => x.CreationTime).ToList();
|
||||
|
||||
for (int i = 0, len = allStreams.Count; i < len; ++i)
|
||||
Console.WriteLine(i + ") " + allStreams[i].LogStreamName);
|
||||
@@ -99,15 +99,28 @@ namespace CloudWatchLogDownloader
|
||||
return ls;
|
||||
}
|
||||
|
||||
private static void WriteLogToFile(LogGroup logGroup, LogStream logStream, string outputFilePath = null)
|
||||
private static void WriteLogToFile(LogGroup logGroup, LogStream logStream, bool liveStream, string outputFilePath = null)
|
||||
{
|
||||
string output = null;
|
||||
if (string.IsNullOrWhiteSpace(outputFilePath))
|
||||
{
|
||||
Console.WriteLine("Choose Output file [logs/" + logStream.LogStreamName + ".log]: ");
|
||||
var output = Console.ReadLine();
|
||||
output = Console.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(output))
|
||||
output = "logs/" + logStream.LogStreamName + ".log";
|
||||
}
|
||||
else
|
||||
{
|
||||
output = outputFilePath;
|
||||
}
|
||||
|
||||
if (!Directory.GetParent(output).Exists)
|
||||
Directory.CreateDirectory(Directory.GetParent(output).FullName);
|
||||
|
||||
Console.WriteLine("Downloading log into " + output);
|
||||
|
||||
bool lsMessage = !liveStream;
|
||||
|
||||
using (StreamWriter sw = new StreamWriter(output))
|
||||
{
|
||||
GetLogEventsResponse leResponse = null;
|
||||
@@ -125,7 +138,17 @@ namespace CloudWatchLogDownloader
|
||||
sw.WriteLine(ev.Message);
|
||||
|
||||
sw.Flush();
|
||||
} while (leResponse.NextForwardToken != null && leResponse.Events.Any());
|
||||
|
||||
if (!leResponse.Events.Any() && !lsMessage)
|
||||
{
|
||||
lsMessage = true;
|
||||
ConsoleColor oldcolor = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("Now streaming live from lg: " + logGroup.LogGroupName + " ls: " + logStream.LogStreamName + " into " + output);
|
||||
Console.ForegroundColor = oldcolor;
|
||||
Console.WriteLine("{0}{0}Press CTRL+C to stop...", Environment.NewLine);
|
||||
}
|
||||
} while ((leResponse.NextForwardToken != null && leResponse.Events.Any()) || liveStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
24
README.md
Normal file
24
README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# CloudWatchLogDownloader
|
||||
Download full logs from AWS CloudWatch
|
||||
|
||||
## Who is it for?
|
||||
For idiots like me who just want a text dump of the cloud watch log without going through S3
|
||||
|
||||
## Why .NET?
|
||||
Because I was working with the .NET AWSSDK when writing this.
|
||||
|
||||
## Why not .NET CORE?
|
||||
Because the AWSSDK.CloudWatchLogs nuget package doesn't support it. (As of writing this README)
|
||||
|
||||
## Usage
|
||||
If you're still reading this means you want to use this abomination... Good.
|
||||
|
||||
### Command line params
|
||||
|short|long|Description|
|
||||
|-----|----|-----------|
|
||||
|-g|--logGroup|The log group you want to select the stream from, can end with '*' in which case the option to choose from all groups starting with this will be given|
|
||||
|-s|--logStream|The log stream you want to save, can end with '*' in which case the option to choose from all groups starting with this will be given|
|
||||
|-o|--outputFile|The file to output the logs to.|
|
||||
|-l|--liveStream|After reaching the newest log keep polling until ctrl+c is pressed|
|
||||
|
||||
If any of the above are not specified the program will prompt for them
|
||||
Reference in New Issue
Block a user