-
Notifications
You must be signed in to change notification settings - Fork 0
Class Jogger
Package jogger
File Jogger.java
Jogger is the principal class to manage the logs.
You can extend me and create your log class. Look
JoggerDebug and
JoggerError, they are
two simple example.
-
-
- void writeLog(String write, String logName, String... splitLogDir)
- void writeLog(String write, String logName, Integer maxSizeBytes, String... splitLogDir)
- String getLogDirPath(String... splitLogDir)
- File getLogFile(String logName, String... splitLogDir)
- File getLogFile(String logName, Integer maxSizeBytes, String... splitLogDir)
- File getLogFileIfExists(String logName, String... splitLogDir)
- File getLogFileIfExists(String logName, Integer maxSizeBytes, String... splitLogDir)
- String getLogFilePath(String logName, String... splitLogDir)
- String getLogFilePath(String logName, Integer maxSizeBytes, String... splitLogDir)
- String getLogFilePathIfExists(String logName, String... splitLogDir)
- String getLogFilePathIfExists(String logName, Integer maxSizeBytes, String... splitLogDir)
-
- String getPrefixLogFile()
- void setPrefixLogFile(String prefixLogFile)
- String getLogName()
- void setLogName(String logName)
- String getFileType()
- void setFileType(String fileType)
- int getMaxSizeBytes(
- void setMaxSizeBytes(int maxSizeBytes)
- boolean isLock()
- void setLock(boolean lock)
- String[] getSplitLogDir()
- void setSplitLogDir(String... splitLogDir)
-
This construct set the path to work on, divided by directory.
Parameters:
- splitLogDir, split path to work on
Example:
// this set the path 'my/path/to/work' Jogger j = new Jogger("my", "path", "to", "work");
This construct set the log name and the path.
Parameters:
- logName, name for log file
- splitLogDir, split path to work on
Example:
// set only logName and use the default log path Jogger j = new Jogger("log_name"); // otherwise Jogger j2 = new Jogger("log_name", "my", "path", "to", "log");
This construct set the log name, max size of log file and the path.
Parameters:
- logName, name for log file
- maxSizeBytes, maximum size of log file, in bytes
- splitLogDir, split path to work on
Example:
// set only logName and max size, use the default log path Jogger j = new Jogger("log_name", 1024000); // otherwise Jogger j2 = new Jogger("log_name", 1024000, "my", "path", "to", "log");
throws LockLogException
This method write a log.
Parameters:
- write, string to be writed
- logName, name for log file
- splitLogDir, split path to work on
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
Jogger.writeLog("startng log", "myapp", "my", "dir");
throws LockLogException
This method write a log.
Parameters:
- write, string to be writed
- logName, name for log file
- maxSizeBytes, maximum size of log file, in bytes
- splitLogDir, split path to work on
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
Jogger.writeLog("startng log", "myapp", 1024000 "my", "dir");
This method get the path of log directory, by directory list passed.
Return:
Return the string of the path formatted for OS.
The path start with the current working directory,
and append to it the folder 'log' with the directory list passed
Parameters:
- splitLogDir, split path
Example:
String path = Jogger.getLogDirPath("my", "dir", "log");
throws LockLogException
This method get a log file.
Return:
Return the log file to work on.
Parameters:
- logName, name of log file
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
File file = Jogger.getLogFile("myapp", "my", "dir", "log");
throws LockLogException
This method get a log file.
Return:
Return the log file to work on.
Parameters:
- logName, name of log file
- maxSizeBytes, maximum size of log file, in bytes
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
File file = Jogger.getLogFile("myapp", 1024000, "my", "dir", "log");
throws LockLogException
This method get a log file if it exists.
Return:
If exists return the log file to work on, null otherwise.
Parameters:
- logName, name of log file
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
File file = Jogger.getLogFileIfExists("myapp", "my", "dir", "log");
throws LockLogException
This method get a log file if it exists.
Return:
If exists return the log file to work on, null otherwise.
Parameters:
- logName, name of log file
- maxSizeBytes, maximum size of log file, in bytes
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
File file = Jogger.getLogFileIfExists("myapp", 1024000, "my", "dir", "log");
throws LockLogException
This method get the path of log file.
Return:
Return the path of log file to work on.
Parameters:
- logName, name of log file
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
String path = Jogger.getLogFilePath("myapp", "my", "dir", "log");
throws LockLogException
This method get the path of log file.
Return:
Return the path of log file to work on.
Parameters:
- logName, name of log file
- maxSizeBytes, maximum size of log file, in bytes
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
String path = Jogger.getLogFilePath("myapp", 1024000, "my", "dir", "log");
throws LockLogException
This method get the path of log file if it exists.
Return:
If exists return the path of log file to work on, null otherwise.
Parameters:
- logName, name of log file
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
File file = Jogger.getLogFile("myapp", "my", "dir", "log");
throws LockLogException
This method get the path of log file if it exists.
Return:
If exists return the path of log file to work on, null otherwise.
Parameters:
- logName, name of log file
- maxSizeBytes, maximum size of log file, in bytes
- splitLogDir, split path to search the log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
File file = Jogger.getLogFile("myapp", 1024000, "my", "dir", "log");
This method get the prefix for log file name.
Default "log_"
Return:
Return the prefix for log file name.
Example:
Jogger jogger = new Jogger(); String string = jogger.getPrefixLogFile();
This method set the prefix for log file name.
Parameters:
- prefixLogFile, prefix for log file name
Example:
Jogger jogger = new Jogger(); jogger.setPrefixLogFile("mylog_");
This method get the log name.
Default "jogger"
Return:
Return the log name.
Example:
Jogger jogger = new Jogger(); String string = jogger.getLogName();
This method set the log name.
Parameters:
- logName, log name
Example:
Jogger jogger = new Jogger(); jogger.setLogName("myapp");
Default ".log"
This method get the log file type.
Return:
Return the log file type.
Example:
Jogger jogger = new Jogger(); String string = jogger.getFileType();
This method set the log file type.
Parameters:
- fileType, log file type
Example:
Jogger jogger = new Jogger(); jogger.setFileType(".log");
This method get the maximum size for log file.
Default 51200
Return:
Return the maximum size, in bytes, for log file.
Example:
Jogger jogger = new Jogger(); int maxSize = jogger.getMaxSizeBytes();
This method set the maximum size for log file.
Parameters:
- maxSizeBytes, maximum size, in bytes, for log file
Example:
Jogger jogger = new Jogger(); jogger.setMaxSizeBytes(1024000);
This method check if the Jogger-Lock is active.
Read Jogger-Lock.
Default false
Return:
Return true if Jogger-Lock is active, false otherwise.
Example:
Jogger jogger = new Jogger(); jogger.setLock(true); if (jogger.isLock()) { //your code }
This method can enable or disable Jogger-Lock.
Read Jogger-Lock.
Parameters:
- lock, true for active it, false otherwise
Example:
Jogger jogger = new Jogger(); jogger.setLock(true);
This method get the split path of log directory.
Default {"jogger"}
Return:
Return the split path of log directory.
Example:
Jogger jogger = new Jogger(); String[] splitPath = jogger.getSplitLogDir();
This method get the split path of log directory.
Parameters:
- splitLogDir, split path to log directory
Example:
Jogger jogger = new Jogger(); jogger.setSplitLogDir("my", "log", "dir");
throws LockLogException
This method write the string passed, on the log.
Implement Jogger-Lock. For more info Jogger-Lock.
Parameters:
- write, string to be writer on log file
Exceptions:
- LockLogException, exception thrown if Jogger-Lock failed
Example:
Jogger jogger = new Jogger(); jogger.writeLog("YEEEEEAAAAHH!!!");
throws LogFileException
This method get the path of log file to work on.
Return:
Return the string with the path of log file to work on.
Exceptions:
- LogFileException, exception thrown if an error is return while working on the log file
Example:
Jogger jogger = new Jogger(); String logFilePath = jogger.getLogFilePath();
throws LogFileException
This method get the log file to work on.
Return:
Return the log file to work on.
Exceptions:
- LogFileException, exception thrown if an error is return while working on the log file
Example:
Jogger jogger = new Jogger(); File logFile = jogger.getFile();
throws LogFileException
This method get the log file to work on, only if it exists.
Return:
If the log file exists return it, otherwise return null.
Exceptions:
- LogFileException, exception thrown if an error is return while working on the log file
Example:
Jogger jogger = new Jogger(); File logFile = jogger.getFileIfExists();
throws LockLogException
This method is used to implement Jogger-Lock.
It check if Jogger-Lock is enable,
then in this case try to lock the file using the class java.util.concurrent.locks.ReentrantLock
.
For more info Jogger-Lock.
Return:
Return true if Jogger-Lock is disable or the lock is successful, false otherwise.
Exceptions:
- LockLogException, exception thrown if the timeout for the lock expires
This method is used to implement Jogger-Lock.
It check if Jogger-Lock is enable,
then in this case unlock the file using the class java.util.concurrent.locks.ReentrantLock
.
For more info Jogger-Lock.