mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added a public method FileLogger::trimFileSize()
This commit is contained in:
parent
2b73de8794
commit
209e91ed8d
2 changed files with 12 additions and 8 deletions
|
|
@ -32,7 +32,7 @@ FileLogger::FileLogger (const File& file,
|
|||
: logFile (file)
|
||||
{
|
||||
if (maxInitialFileSizeBytes >= 0)
|
||||
trimFileSize (maxInitialFileSizeBytes);
|
||||
trimFileSize (logFile, maxInitialFileSizeBytes);
|
||||
|
||||
if (! file.exists())
|
||||
file.create(); // (to create the parent directories)
|
||||
|
|
@ -57,23 +57,23 @@ void FileLogger::logMessage (const String& message)
|
|||
out << message << newLine;
|
||||
}
|
||||
|
||||
void FileLogger::trimFileSize (int64 maxFileSizeBytes) const
|
||||
void FileLogger::trimFileSize (const File& file, int64 maxFileSizeBytes)
|
||||
{
|
||||
if (maxFileSizeBytes <= 0)
|
||||
{
|
||||
logFile.deleteFile();
|
||||
file.deleteFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
const int64 fileSize = logFile.getSize();
|
||||
const int64 fileSize = file.getSize();
|
||||
|
||||
if (fileSize > maxFileSizeBytes)
|
||||
{
|
||||
TemporaryFile tempFile (logFile);
|
||||
TemporaryFile tempFile (file);
|
||||
|
||||
{
|
||||
FileOutputStream out (tempFile.getFile());
|
||||
FileInputStream in (logFile);
|
||||
FileInputStream in (file);
|
||||
|
||||
if (! (out.openedOk() && in.openedOk()))
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -121,13 +121,17 @@ public:
|
|||
// (implementation of the Logger virtual method)
|
||||
void logMessage (const String&);
|
||||
|
||||
//==============================================================================
|
||||
/** This is a utility function which removes lines from the start of a text
|
||||
file to make sure that its total size is below the given size.
|
||||
*/
|
||||
static void trimFileSize (const File& file, int64 maxFileSize);
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
File logFile;
|
||||
CriticalSection logLock;
|
||||
|
||||
void trimFileSize (int64 maxFileSizeBytes) const;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileLogger)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue