-
Notifications
You must be signed in to change notification settings - Fork 73
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
Adding rolled custom logs in support bundle #627
base: master
Are you sure you want to change the base?
Adding rolled custom logs in support bundle #627
Conversation
Test failure sounds legitimate. |
@@ -95,6 +95,30 @@ public Iterable<LogRecord> getLogRecords() { | |||
} | |||
}); | |||
} | |||
|
|||
// Add rotated log files | |||
File[] rotatedLogFiles = customLogs.listFiles((dir, filename) -> filename.matches(name + "\\.log\\.\\d+")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I find
File[] rotatedLogFiles = customLogs.listFiles((dir, filename) -> filename.matches(name + "\\.log\\.\\d+")); | |
File[] rotatedLogFiles = customLogs.listFiles((dir, filename) -> filename.matches(name + "[.]log[.][0-9]+")); |
a bit more legible (so I do not need to mentally parse out backslashes).
String logRotationNumber = logNameParts[logNameParts.length - 1]; | ||
|
||
result.add( | ||
new FileContent(rotatedEntryName, new String[] {name, logRotationNumber}, rotatedLogFile)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logRotationNumber
is not actually a “filterable parameter”. name
would be.
src/main/java/com/cloudbees/jenkins/support/impl/CustomLogs.java
Outdated
Show resolved
Hide resolved
try (FileWriter writer = new FileWriter(new File(customLogsDir, "test1.log"))) { | ||
writer.write("test1 one"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a Files
method for this
Co-authored-by: Jesse Glick <jglick@cloudbees.com>
@@ -44,7 +44,7 @@ public class CustomLogs extends Component { | |||
|
|||
private static final Logger LOGGER = Logger.getLogger(CustomLogs.class.getName()); | |||
private static final int MAX_ROTATE_LOGS = Integer.getInteger(CustomLogs.class.getName() + ".MAX_ROTATE_LOGS", 9); | |||
private static final File customLogs = new File(SafeTimerTask.getLogsRoot(), "custom"); | |||
private final File customLogs = new File(SafeTimerTask.getLogsRoot(), "custom"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed static as when I was running a test class, [CustomLogsTest.java]
, it has 3 test in it for some reason SafeTimerTask.getLogsRoot()
was same for all test , due to which test were failing ,
removing static fixed this , i think its similar to #617 (comment)
[edited, please paste raw discussion permalinks]
} | ||
} | ||
|
||
private static final class LogFile { | ||
private final RewindableRotatingFileOutputStream stream; | ||
private final Handler handler; | ||
private int count; | ||
private final File customLogs = new File(SafeTimerTask.getLogsRoot(), "custom"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or pass it in the constructor.
try (FileWriter writer = new FileWriter(new File(customLogsDir, "nonRotatedCustomLog.log"))) { | ||
writer.write("nonRotatedCustomLog one"); | ||
} | ||
Files.write(Paths.get(customLogsDir.getPath(), "test1.log"), "test1 one".getBytes(), StandardOpenOption.CREATE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just
Files.write(Paths.get(customLogsDir.getPath(), "test1.log"), "test1 one".getBytes(), StandardOpenOption.CREATE); | |
Files.write(Paths.get(customLogsDir.getPath(), "test1.log"), "test1 one".getBytes()); |
suffices (ditto elsewhere)
|
No description provided.