Roll instrumentation log files.

Keep up to 5 old log files.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org/1418143006 .
This commit is contained in:
Konstantin Shcheglov 2015-11-05 08:40:43 -08:00
parent abcb3a4d4d
commit 61ee6dff5f

View file

@ -383,6 +383,7 @@ class Driver implements ServerStarter {
//
String logFilePath = results[INSTRUMENTATION_LOG_FILE];
if (logFilePath != null) {
_rollLogFiles(logFilePath, 5);
FileInstrumentationServer fileBasedServer =
new FileInstrumentationServer(logFilePath);
instrumentationServer = instrumentationServer != null
@ -577,4 +578,20 @@ class Driver implements ServerStarter {
}
return uuid;
}
/**
* Perform log files rolling.
*
* Rename existing files with names `[path].(x)` to `[path].(x+1)`.
* Keep at most [numOld] files.
* Rename the file with the given [path] to `[path].1`.
*/
static void _rollLogFiles(String path, int numOld) {
for (int i = numOld - 1; i >= 0; i--) {
try {
String oldPath = i == 0 ? path : '$path.$i';
new File(oldPath).renameSync('$path.${i+1}');
} catch (e) {}
}
}
}