JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_FileLogger.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
29 : logFile (file)
30{
33
34 if (! file.exists())
35 file.create(); // (to create the parent directories)
36
39 << "**********************************************************" << newLine
41 << "Log started: " << Time::getCurrentTime().toString (true, true) << newLine;
42
44}
45
47
48//==============================================================================
49void FileLogger::logMessage (const String& message)
50{
51 const ScopedLock sl (logLock);
52 DBG (message);
53 FileOutputStream out (logFile, 256);
54 out << message << newLine;
55}
56
58{
59 if (maxFileSizeBytes <= 0)
60 {
61 file.deleteFile();
62 }
63 else
64 {
65 const int64 fileSize = file.getSize();
66
67 if (fileSize > maxFileSizeBytes)
68 {
70
71 {
72 FileOutputStream out (tempFile.getFile());
73 FileInputStream in (file);
74
75 if (! (out.openedOk() && in.openedOk()))
76 return;
77
78 in.setPosition (fileSize - maxFileSizeBytes);
79
80 for (;;)
81 {
82 const char c = in.readByte();
83 if (c == 0)
84 return;
85
86 if (c == '\n' || c == '\r')
87 {
88 out << c;
89 break;
90 }
91 }
92
93 out.writeFromInputStream (in, -1);
94 }
95
96 tempFile.overwriteTargetFileWithTemporary();
97 }
98 }
99}
100
101//==============================================================================
103{
104 #if JUCE_MAC
105 return File ("~/Library/Logs");
106 #else
108 #endif
109}
110
120
122 const String& logFileNameRoot,
124 const String& welcomeMessage)
125{
127 .getChildFile (logFileNameRoot + Time::getCurrentTime().formatted ("%Y-%m-%d_%H-%M-%S"))
128 .withFileExtension (logFileNameSuffix)
129 .getNonexistentSibling(),
130 welcomeMessage, 0);
131}
132
133} // namespace juce
An input stream that reads from a local file.
bool setPosition(int64) override
Tries to move the current read position of the stream.
bool openedOk() const noexcept
Returns true if the stream opened without problems.
A simple implementation of a Logger that writes to a file.
FileLogger(const File &fileToWriteTo, const String &welcomeMessage, const int64 maxInitialFileSizeBytes=128 *1024)
Creates a FileLogger for a given file.
static FileLogger * createDefaultAppLogger(const String &logFileSubDirectoryName, const String &logFileName, const String &welcomeMessage, const int64 maxInitialFileSizeBytes=128 *1024)
Helper function to create a log file in the correct place for this platform.
static void trimFileSize(const File &file, int64 maxFileSize)
This is a utility function which removes lines from the start of a text file to make sure that its to...
static File getSystemLogFileFolder()
Returns an OS-specific folder where log-files should be stored.
~FileLogger() override
Destructor.
static FileLogger * createDateStampedLogger(const String &logFileSubDirectoryName, const String &logFileNameRoot, const String &logFileNameSuffix, const String &welcomeMessage)
Helper function to create a log file in the correct place for this platform.
void logMessage(const String &) override
This is overloaded by subclasses to implement custom logging behaviour.
An output stream that writes into a local file.
bool openedOk() const noexcept
Returns true if the stream opened without problems.
Represents a local file or directory.
Definition juce_File.h:45
int64 getSize() const
Returns the size of the file in bytes.
@ userApplicationDataDirectory
The folder in which applications store their persistent user-specific settings.
Definition juce_File.h:895
Result create() const
Creates an empty file if it doesn't already exist.
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
Finds the location of a special type of file or directory, such as a home folder or documents folder.
bool deleteFile() const
Deletes a file.
bool exists() const
Checks whether the file actually exists.
Automatically locks and unlocks a mutex object.
virtual char readByte()
Reads a byte from the stream.
virtual int64 writeFromInputStream(InputStream &source, int64 maxNumBytesToWrite)
Reads data from an input stream and writes it to this stream.
The JUCE String class!
Definition juce_String.h:53
Manages a temporary file, which will be deleted when this object is deleted.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
String toString(bool includeDate, bool includeTime, bool includeSeconds=true, bool use24HourClock=false) const
Returns a string version of this date and time, using this machine's local timezone.
#define DBG(textToWrite)
Writes a string to the standard error stream.
JUCE Namespace.
NewLine newLine
A predefined object representing a new-line, which can be written to a string or stream.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
long long int64
A platform-independent 64-bit integer type.