Class TempLogFile
- java.lang.Object
-
- org.opends.quicksetup.TempLogFile
-
public class TempLogFile extends Object
This class represents a temporary log file which should be usually deleted if linked operation succeeded.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeleteLogFileAfterSuccess()Closes the log file handler and delete the temp log file .FilegetLogFile()Gets the name of the log file.StringgetPath()Return the absolute path of the temp log file.booleanisEnabled()Returntrueif a temp log file has been created and could be used to log messages.booleanisReadable()Returntrueif the temp log file is still on disk and can be read.static TempLogFilenewTempLogFile(String prefix)Creates a new temporary log file.static TempLogFilenewTempLogFile(String prefix, File directory)Creates a new temporary log file in the given directory.StringreadContents()Reads the whole temp log file.
-
-
-
Method Detail
-
newTempLogFile
public static TempLogFile newTempLogFile(String prefix)
Creates a new temporary log file.Log file will be generated in the OS temporary directory and its name will have the following pattern: prefix-[RANDOM_NUMBER_STRING].log
- Parameters:
prefix- log file prefix to which log messages will be written.- Returns:
- a new temporary log file.
-
newTempLogFile
public static TempLogFile newTempLogFile(String prefix, File directory)
Creates a new temporary log file in the given directory.The directory is created if it does not exist yet. When it is
nullor cannot be used, the log file goes to the OS temporary directory instead, as withnewTempLogFile(String). The name of the file follows the pattern prefix-[RANDOM_NUMBER_STRING].log either way.- Parameters:
prefix- log file prefix to which log messages will be written.directory- the directory to create the log file in, ornullfor the OS temporary directory.- Returns:
- a new temporary log file.
-
getLogFile
public File getLogFile()
Gets the name of the log file.- Returns:
- File representing the log file
-
deleteLogFileAfterSuccess
public void deleteLogFileAfterSuccess()
Closes the log file handler and delete the temp log file .The publishers installed by the constructor go with it: they are held by the logger singletons, which outlive this object, and once the writer is shut everything they are handed is written to a closed stream and swallowed.
-
isEnabled
public boolean isEnabled()
Returntrueif a temp log file has been created and could be used to log messages.- Returns:
trueif a temp log file has been created and could be used to log messages.
-
isReadable
public boolean isReadable()
Returntrueif the temp log file is still on disk and can be read.Unlike
isEnabled()this is about the file, not the logger: something else may have removed the file while the logger still writes to it (see issue #1030), and then there is nothing to hand over to whoever needs the log.- Returns:
trueif the temp log file is there and readable.
-
readContents
public String readContents() throws IOException
Reads the whole temp log file.The file is decoded with the default charset of the JVM, which is the one
TextWriter.STREAMwrote it with: reader and writer are the same JVM, so a non-ASCII path or base DN in a report comes back as it was logged.- Returns:
- the contents of the temp log file.
- Throws:
IOException- if the file cannot be read, for instance because it is no longer there.
-
getPath
public String getPath()
Return the absolute path of the temp log file.- Returns:
- the absolute path of the temp log file.
-
-