-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logging package and logging properties config file
- Loading branch information
Ilias
committed
Mar 12, 2013
1 parent
9119177
commit 5587bbf
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Properties file which configures the operation of the JDK | ||
# logging facility. | ||
|
||
# The system will look for this config file, first using | ||
# a System property specified at startup: | ||
# | ||
# >java -Djava.util.logging.config.file=myLoggingConfigFilePath | ||
# | ||
# If this property is not specified, then the config file is | ||
# retrieved from its default location at: | ||
# | ||
# JDK_HOME/jre/lib/logging.properties | ||
|
||
# Global logging properties. | ||
# ------------------------------------------ | ||
# The set of handlers to be loaded upon startup. | ||
# Comma-separated list of class names. | ||
# (? LogManager docs say no comma here, but JDK example has comma.) | ||
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler | ||
|
||
# Default global logging level. | ||
# Loggers and Handlers may override this level | ||
# logging levels: SEVERE>INFO>FINE & OFF & ALL | ||
.level=FINE | ||
|
||
# Loggers | ||
# ------------------------------------------ | ||
# Loggers are usually attached to packages. | ||
# Here, the level for each package is specified. | ||
# The global level is used by default, so levels | ||
# specified here simply act as an override. | ||
myapp.ui.level=ALL | ||
myapp.business.level=CONFIG | ||
myapp.data.level=SEVERE | ||
|
||
# Handlers | ||
# ----------------------------------------- | ||
|
||
# --- ConsoleHandler --- | ||
# Override of global logging level | ||
java.util.logging.ConsoleHandler.level=SEVERE | ||
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter | ||
|
||
# --- FileHandler --- | ||
# Override of global logging level | ||
java.util.logging.FileHandler.level=ALL | ||
|
||
# Naming style for the output file: | ||
# (The output file is placed in the directory | ||
# defined by the "user.home" System property.) | ||
java.util.logging.FileHandler.pattern=%h/deeco_core%u.log | ||
|
||
# Limiting size of output file in bytes: | ||
java.util.logging.FileHandler.limit=50000 | ||
|
||
# Number of output files to cycle through, by appending an | ||
# integer to the base file name: | ||
java.util.logging.FileHandler.count=1 | ||
|
||
# Style of output (Simple or XML): | ||
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter |
36 changes: 36 additions & 0 deletions
36
jdeeco-core/src/cz/cuni/mff/d3s/deeco/logging/ILogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cz.cuni.mff.d3s.deeco.logging; | ||
|
||
/** | ||
* Common abstraction for OSGi-based & non OSGi-based Loggers exposing 3 logging | ||
* methods for 3 logging levels. | ||
* | ||
* @author Ilias Gerostathopoulos | ||
* | ||
*/ | ||
public interface ILogger { | ||
|
||
/** | ||
* For reporting exceptions & errors. | ||
* | ||
* @param msg | ||
* the string message | ||
*/ | ||
public void severe(String msg); | ||
|
||
/** | ||
* General logging method. | ||
* | ||
* @param msg | ||
* the string message | ||
*/ | ||
public void info(String msg); | ||
|
||
/** | ||
* For debugging reasons. | ||
* | ||
* @param msg | ||
* the string message | ||
*/ | ||
public void fine(String msg); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
jdeeco-core/src/cz/cuni/mff/d3s/deeco/logging/LoggerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cz.cuni.mff.d3s.deeco.logging; | ||
|
||
/** | ||
* Chooses between Standard- and OSGiLogger (once we have the last one), based | ||
* on runtime information. For now, it just returns the StandardLogger object. | ||
* | ||
* @author Ilias Gerostathopoulos | ||
* | ||
*/ | ||
public class LoggerFactory { | ||
|
||
public static ILogger getLogger() { | ||
return StandardLogger.getLogger(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
jdeeco-core/src/cz/cuni/mff/d3s/deeco/logging/StandardLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package cz.cuni.mff.d3s.deeco.logging; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.logging.LogManager; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Simple wrapper of java.util.logging.Logger with singleton object and | ||
* thread-safe methods | ||
* | ||
* @author Ilias Gerostathopoulos | ||
* | ||
*/ | ||
public class StandardLogger implements ILogger { | ||
|
||
private static ILogger instance; | ||
private Logger logger; | ||
|
||
private StandardLogger() { | ||
logger = Logger.getLogger(this.getClass().getPackage().getName()); | ||
InputStream inputStream = getClass().getClassLoader() | ||
.getResourceAsStream("logging.properties"); | ||
try { | ||
LogManager.getLogManager().readConfiguration(inputStream); | ||
} catch (IOException e) { | ||
Logger.getAnonymousLogger().severe( | ||
"Could not load custom logging.properties file"); | ||
Logger.getAnonymousLogger().severe(e.getMessage()); | ||
} | ||
} | ||
|
||
public static ILogger getLogger() { | ||
if (instance == null) { | ||
synchronized (StandardLogger.class) { | ||
if (instance == null) { | ||
instance = new StandardLogger(); | ||
} | ||
} | ||
} | ||
return instance; | ||
} | ||
|
||
public synchronized void severe(String s) { | ||
logger.severe(s); | ||
} | ||
|
||
public synchronized void info(String s) { | ||
logger.info(s); | ||
} | ||
|
||
public synchronized void fine(String s) { | ||
logger.fine(s); | ||
} | ||
|
||
} |