mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-06 15:55:47 +02:00
[232738] [dstore] Delay creation of log file until written to
This commit is contained in:
parent
8cc3815e48
commit
f8cbab53fc
1 changed files with 33 additions and 17 deletions
|
@ -13,6 +13,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
|
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
|
||||||
* David McKnight (IBM) - [226086] [dstore][api][breaking] Move ServerLogger class to dstore.core
|
* David McKnight (IBM) - [226086] [dstore][api][breaking] Move ServerLogger class to dstore.core
|
||||||
|
* Jacob Garcowski (IBM) - [232738] [dstore] Delay creation of log file until written to
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.dstore.core.server;
|
package org.eclipse.dstore.core.server;
|
||||||
|
@ -47,6 +48,10 @@ public class ServerLogger implements IServerLogger
|
||||||
|
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
private static int log_level = 0;
|
private static int log_level = 0;
|
||||||
|
|
||||||
|
private boolean initialized = false;
|
||||||
|
private String logPathName = null;
|
||||||
|
private boolean logToFile = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new ServerLogger.
|
* Constructs a new ServerLogger.
|
||||||
|
@ -54,24 +59,27 @@ public class ServerLogger implements IServerLogger
|
||||||
* @param logPathName the path on the filesystem to store the log information
|
* @param logPathName the path on the filesystem to store the log information
|
||||||
*/
|
*/
|
||||||
public ServerLogger(String logPathName) {
|
public ServerLogger(String logPathName) {
|
||||||
if (_logFileStream == null) {
|
this.logPathName = logPathName;
|
||||||
// Read .properties file to configure
|
// Read .properties file to configure
|
||||||
boolean logToFile = true;
|
try {
|
||||||
|
ResourceBundle properties = ResourceBundle.getBundle("rsecomm"); //$NON-NLS-1$
|
||||||
try {
|
String debug_level = properties.getString(DEBUG_LEVEL).trim();
|
||||||
ResourceBundle properties = ResourceBundle.getBundle("rsecomm"); //$NON-NLS-1$
|
log_level = Integer.parseInt(debug_level);
|
||||||
String debug_level = properties.getString(DEBUG_LEVEL).trim();
|
String log_location = properties.getString(LOG_LOCATION).trim();
|
||||||
log_level = Integer.parseInt(debug_level);
|
if (log_location.equalsIgnoreCase(LOG_TO_STDOUT)) {
|
||||||
String log_location = properties.getString(LOG_LOCATION).trim();
|
logToFile = false;
|
||||||
if (log_location.equalsIgnoreCase(LOG_TO_STDOUT)) {
|
_logFileStream = new PrintWriter(System.out);
|
||||||
logToFile = false;
|
|
||||||
_logFileStream = new PrintWriter(System.out);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Just use logging defaults: log_level = 0, log to file
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Just use logging defaults: log_level = 0, log to file
|
||||||
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize()
|
||||||
|
{
|
||||||
|
initialized = true;
|
||||||
|
if (_logFileStream == null) {
|
||||||
if (logToFile) {
|
if (logToFile) {
|
||||||
try {
|
try {
|
||||||
File _logFile = new File(logPathName, "rsecomm.log"); //$NON-NLS-1$
|
File _logFile = new File(logPathName, "rsecomm.log"); //$NON-NLS-1$
|
||||||
|
@ -97,6 +105,8 @@ public class ServerLogger implements IServerLogger
|
||||||
* @param message Message text to be logged.
|
* @param message Message text to be logged.
|
||||||
*/
|
*/
|
||||||
public void logInfo(String minerName, String message) {
|
public void logInfo(String minerName, String message) {
|
||||||
|
if (!initialized)
|
||||||
|
initialize();
|
||||||
if (log_level >= LOG_INFO) {
|
if (log_level >= LOG_INFO) {
|
||||||
if (_logFileStream != null) {
|
if (_logFileStream != null) {
|
||||||
synchronized(writeLock) {
|
synchronized(writeLock) {
|
||||||
|
@ -119,6 +129,8 @@ public class ServerLogger implements IServerLogger
|
||||||
* @param message Message text to be logged.
|
* @param message Message text to be logged.
|
||||||
*/
|
*/
|
||||||
public void logWarning(String minerName, String message) {
|
public void logWarning(String minerName, String message) {
|
||||||
|
if (!initialized)
|
||||||
|
initialize();
|
||||||
if (log_level >= LOG_WARNING) {
|
if (log_level >= LOG_WARNING) {
|
||||||
if (_logFileStream != null) {
|
if (_logFileStream != null) {
|
||||||
synchronized(writeLock) {
|
synchronized(writeLock) {
|
||||||
|
@ -143,6 +155,8 @@ public class ServerLogger implements IServerLogger
|
||||||
* @param exception Exception that generated the error. Used to print a stack trace.
|
* @param exception Exception that generated the error. Used to print a stack trace.
|
||||||
*/
|
*/
|
||||||
public void logError(String minerName, String message, Throwable exception) {
|
public void logError(String minerName, String message, Throwable exception) {
|
||||||
|
if (!initialized)
|
||||||
|
initialize();
|
||||||
if (_logFileStream != null) {
|
if (_logFileStream != null) {
|
||||||
synchronized(writeLock) {
|
synchronized(writeLock) {
|
||||||
try {
|
try {
|
||||||
|
@ -166,6 +180,8 @@ public class ServerLogger implements IServerLogger
|
||||||
* @param message Message text to be logged.
|
* @param message Message text to be logged.
|
||||||
*/
|
*/
|
||||||
public synchronized void logDebugMessage(String minerName, String message) {
|
public synchronized void logDebugMessage(String minerName, String message) {
|
||||||
|
if (!initialized)
|
||||||
|
initialize();
|
||||||
if (DEBUG && log_level == LOG_DEBUG) {
|
if (DEBUG && log_level == LOG_DEBUG) {
|
||||||
if (_logFileStream != null) {
|
if (_logFileStream != null) {
|
||||||
synchronized(writeLock) {
|
synchronized(writeLock) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue