Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 20595 Details for
Bug 87504
Log size limits and rotating logs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch to EclipseLog.java
patch.txt (text/plain), 4.83 KB, created by
Julian Chen
on 2005-05-02 11:43:39 EDT
(
hide
)
Description:
Patch to EclipseLog.java
Filename:
MIME Type:
Creator:
Julian Chen
Created:
2005-05-02 11:43:39 EDT
Size:
4.83 KB
patch
obsolete
>Index: EclipseLog.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseLog.java,v >retrieving revision 1.19 >diff -u -r1.19 EclipseLog.java >--- EclipseLog.java 25 Apr 2005 21:07:42 -0000 1.19 >+++ EclipseLog.java 2 May 2005 15:33:27 -0000 >@@ -51,9 +51,23 @@ > */ > protected Writer writer; > >+ public static final int DEFAULT_LOG_SIZE = 1000; //$NON-NLS-1$ >+ public static final int MIN_LOG_SIZE = 10; //$NON-NLS-1$ >+ public static final int DEFAULT_LOG_FILES = 1; //$NON-NLS-1$ >+ >+ public static final String LOG_SIZE_MAX = "eclipse.log.size.max"; //$NON-NLS-1$ >+ public static final String LOG_FILE_MAX = "eclipse.log.backup.max"; //$NON-NLS-1$ >+ public static final String LOG_EXT = ".log"; //$NON-NLS-1$ >+ public static final String BACKUP_MARK = ".bak_"; //$NON-NLS-1$ >+ >+ int maxLogSize = DEFAULT_LOG_SIZE; // The value is in KB. >+ int maxLogFiles = DEFAULT_LOG_FILES; >+ int backupIdx = 0; >+ > public EclipseLog(File outFile) { > this.outFile = outFile; > this.writer = null; >+ readLogProperties(); > } > > public EclipseLog(Writer writer) { >@@ -216,6 +230,7 @@ > if (logEntry == null) > return; > try { >+ checkLogFileSize(); > openFile(); > if (newSession) { > writeSession(); >@@ -247,6 +262,11 @@ > } > > public synchronized void setFile(File newFile, boolean append) throws IOException { >+ if (newFile != null && !newFile.equals(this.outFile)) { >+ // If it's a new file, then reset. >+ readLogProperties(); >+ backupIdx = 0; >+ } > setOutput(newFile, null, append); > System.getProperties().put(EclipseStarter.PROP_LOGFILE, newFile.getAbsolutePath()); > } >@@ -414,4 +434,88 @@ > protected void writeSpace() throws IOException { > write(" "); //$NON-NLS-1$ > } >+ >+ protected boolean checkLogFileSize() { >+ if (maxLogSize == 0) >+ return true; // no size limitation. >+ >+ boolean isBackupOK = true; >+ if (outFile != null) { >+ if ((outFile.length()>>10) > maxLogSize) { // Use KB as file size unit. >+ String logFilename = outFile.getAbsolutePath(); >+ >+ // Delete old backup file that will be replaced. >+ String replacedFilename = ""; //$NON-NLS-1$ >+ if (logFilename.toLowerCase().endsWith(LOG_EXT)) { >+ replacedFilename = >+ logFilename.substring(0, logFilename.length()-LOG_EXT.length()) >+ + BACKUP_MARK + backupIdx + LOG_EXT; >+ } >+ else { >+ replacedFilename = logFilename + BACKUP_MARK + backupIdx; //$NON-NLS-1$ >+ } >+ File replacedFile = new File(replacedFilename); >+ if (replacedFile.exists()) { >+ if (!replacedFile.delete()) { >+ System.err.println("Error when trying to delete old log file: " //$NON-NLS-1$ >+ + replacedFile.getName()); >+ if (replacedFile.renameTo(new File(replacedFile.getAbsolutePath() + System.currentTimeMillis()))) { >+ System.err.println("So we rename it to filename: " + replacedFile.getName()); //$NON-NLS-1$ >+ } >+ else { >+ System.err.println("And we also cannot rename it!"); //$NON-NLS-1$ >+ isBackupOK = false; >+ } >+ } >+ } >+ >+ // Rename current log file to backup one. >+ boolean isRenameOK = outFile.renameTo(replacedFile); >+ if (!isRenameOK) { >+ System.err.println("Error when trying to rename log file to backup one."); //$NON-NLS-1$ >+ isBackupOK = false; >+ } >+ File newFile = new File(logFilename); >+ setOutput(newFile, null, false); >+ >+ // Write a new SESSION header to new log file. >+ openFile(); >+ try { >+ writeSession(); >+ writeln(); >+ writeln("This is a continuation of log file " //$NON-NLS-1$ >+ + replacedFile.getPath()); >+ writeln("Created Time: " + getDate(new Date(System.currentTimeMillis()))); //$NON-NLS-1$ >+ writer.flush(); >+ } >+ catch (IOException ioe) { >+ ioe.printStackTrace(); >+ } >+ closeFile(); >+ backupIdx = (++backupIdx) % maxLogFiles; >+ } >+ } >+ return isBackupOK; >+ } >+ >+ protected void readLogProperties() { >+ Object maxLogSize_obj = System.getProperties().get(LOG_SIZE_MAX); >+ if (maxLogSize_obj != null && maxLogSize_obj instanceof Integer) { >+ maxLogSize = ((Integer) maxLogSize_obj).intValue(); >+ if (maxLogSize != 0 && maxLogSize < MIN_LOG_SIZE) { >+ // If the value is '0', then it means no size limitation. >+ // Also, make sure no inappropriate(too small) assigned value. >+ maxLogSize = MIN_LOG_SIZE; >+ } >+ } >+ >+ Object maxLogFiles_obj = System.getProperties().get(LOG_FILE_MAX); >+ if (maxLogFiles_obj != null && maxLogFiles_obj instanceof Integer) { >+ maxLogFiles = ((Integer) maxLogFiles_obj).intValue(); >+ if (maxLogFiles < 1) { >+ // Make sure no invalid assigned value. (at least >= 1) >+ maxLogFiles = DEFAULT_LOG_FILES; >+ } >+ } >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 87504
: 20595