Skip to content

Commit

Permalink
- Polished the documentation.
Browse files Browse the repository at this point in the history
- Polished the synchronization.
  • Loading branch information
carlspring committed Mar 14, 2016
1 parent feed3d0 commit 0d946de
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 25 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
This is an API for configuring logback programatically.

Currently, the implementation contains:
* A service layer (using Spring) located in the logback-configuration-core module
* A service layer (using Spring) located in the logback-configuration-core module which provides methods to:
** Add loggers based on a package, level and appenderName
** Update an existing logger
** Delete an existing logger
** Resolve a log file
** Resolve the Logback configuration file
** Upload a Logback configuration file and reload it
* A simple REST implementation (using Jersey) located in the logback-configuration-rest module
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,64 @@
public interface LoggingManagementService
{

/**
* Adds a logger with the specified level and appender.
*
* @param loggerPackage
* @param level
* @param appenderName
* @throws LoggingConfigurationException
* @throws AppenderNotFoundException
*/
void addLogger(String loggerPackage, String level, String appenderName)
throws LoggingConfigurationException, AppenderNotFoundException;

/**
* Updates an existing logger.
*
* @param loggerPackage
* @param level
* @throws LoggingConfigurationException
* @throws LoggerNotFoundException
*/
void updateLogger(String loggerPackage, String level)
throws LoggingConfigurationException, LoggerNotFoundException;

/**
* Deletes a logger.
*
* @param loggerPackage
* @throws LoggingConfigurationException
* @throws LoggerNotFoundException
*/
void deleteLogger(String loggerPackage)
throws LoggingConfigurationException, LoggerNotFoundException;


/**
* This method resolves an InputStream to a log file.
*
* @param logFilePath
* @return
* @throws LoggingConfigurationException
*/
InputStream downloadLog(String logFilePath)
throws LoggingConfigurationException;


/**
* This method resolves an InputStream to the logback configuration file.
*
* @return
* @throws LoggingConfigurationException
*/
InputStream downloadLogbackConfiguration()
throws LoggingConfigurationException;


/**
* This method overwrites the existing logback configuration file with a specified one.
*
* @param inputStream
* @throws LoggingConfigurationException
*/
void uploadLogbackConfiguration(InputStream inputStream)
throws LoggingConfigurationException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LoggingManagementServiceImpl

private static final org.slf4j.Logger logger = LoggerFactory.getLogger(LoggingManagementServiceImpl.class);

private Object lock = new Object();
private final Object lock = new Object();

private List<String> asList = Arrays.asList("ALL",
"DEBUG",
Expand Down Expand Up @@ -172,24 +172,7 @@ public InputStream downloadLogbackConfiguration()

dumpLoggingProperties();

File file;
URL url = LoggingManagementServiceImpl.class.getClassLoader().getResource(path);
if (url != null)
{
logger.debug("Resolved the Logback configuration class from the classpath (" + url.toURI() + ").");

file = new File(url.toURI());
}
else
{
file = new File(path);
if (!file.exists())
{
throw new FileNotFoundException("Failed to locate the Logback configuration file!");
}

logger.debug("Resolved the Logback configuration class from the file system (" + file.getAbsolutePath() + ").");
}
File file = resolveLogbackConfigurationFile(path);

logger.debug("Downloading configuration file " + file.getAbsolutePath() + "...");

Expand All @@ -215,8 +198,7 @@ public void uploadLogbackConfiguration(InputStream is)

String path = pathToXml != null ? pathToXml : "logback.xml";

URL url = LoggingManagementServiceImpl.class.getClassLoader().getResource(path);
File file = new File(url.toURI());
File file = resolveLogbackConfigurationFile(path);

fos = new FileOutputStream(file);
int readLength;
Expand Down Expand Up @@ -244,6 +226,29 @@ public void uploadLogbackConfiguration(InputStream is)
}
}

private File resolveLogbackConfigurationFile(String path) throws URISyntaxException, FileNotFoundException
{
File file;
URL url = LoggingManagementServiceImpl.class.getClassLoader().getResource(path);
if (url != null)
{
logger.debug("Resolved the Logback configuration class from the classpath (" + url.toURI() + ").");

file = new File(url.toURI());
}
else
{
file = new File(path);
if (!file.exists())
{
throw new FileNotFoundException("Failed to locate the Logback configuration file!");
}

logger.debug("Resolved the Logback configuration class from the file system (" + file.getAbsolutePath() + ").");
}
return file;
}

@Override
public String getPathToXml()
{
Expand Down

0 comments on commit 0d946de

Please sign in to comment.