Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
Refactor log methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Jul 1, 2016
1 parent 62dad6e commit d422404
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 39 deletions.
Expand Up @@ -16,8 +16,9 @@
import melnorme.lang.ide.core.project_model.BundleModelManager; import melnorme.lang.ide.core.project_model.BundleModelManager;
import melnorme.lang.ide.core.project_model.LangBundleModel; import melnorme.lang.ide.core.project_model.LangBundleModel;
import melnorme.utilbox.misc.ILogHandler; import melnorme.utilbox.misc.ILogHandler;
import melnorme.utilbox.status.StatusException;


public abstract class AbstractLangCore { public abstract class AbstractLangCore extends LoggingCore {


public static LangCore instance; public static LangCore instance;


Expand Down Expand Up @@ -54,7 +55,7 @@ protected void shutdown() {


/* ----------------- ----------------- */ /* ----------------- ----------------- */


public static ILogHandler logHandler() { public static ILogHandler log() {
return instance.logHandler; return instance.logHandler;
} }


Expand Down Expand Up @@ -94,4 +95,44 @@ public void startAgentsAfterUIStart() {
bundleManager.startManager(); bundleManager.startManager();
} }


}

class LoggingCore {

public static ILogHandler log() {
return AbstractLangCore.instance.logHandler;
}

/** Logs status of given StatusException. */
public static void logStatusException(StatusException se) {
log().logStatus(se);
}

/** Logs an error status with given message. */
public static void logError(String message) {
log().logError(message);
}
/** Logs an error status with given message and given throwable. */
public static void logError(String message, Throwable throwable) {
log().logError(message, throwable);
}

/** Logs a warning status with given message. */
public static void logWarning(String message) {
log().logWarning(message);
}
/** Logs a warning status with given message and given throwable. */
public static void logWarning(String message, Throwable throwable) {
log().logWarning(message, throwable);
}

/** Logs an info status with given message. */
public static void logInfo(String message) {
log().logInfo(message);
}

public static void logInternalError(Throwable throwable) {
log().logError("Internal Error!", throwable);
}

} }
36 changes: 0 additions & 36 deletions plugin_ide.core/src-lang/melnorme/lang/ide/core/LangCore.java
Expand Up @@ -11,47 +11,11 @@
package melnorme.lang.ide.core; package melnorme.lang.ide.core;


import melnorme.utilbox.misc.ILogHandler; import melnorme.utilbox.misc.ILogHandler;
import melnorme.utilbox.status.Severity;
import melnorme.utilbox.status.StatusException;


public class LangCore extends LangCore_Actual { public class LangCore extends LangCore_Actual {


public LangCore(ILogHandler logHandler) { public LangCore(ILogHandler logHandler) {
super(logHandler); super(logHandler);
} }


/* ----------------- Logging ----------------- */

/** Logs status of given StatusException. */
public static void logStatusException(StatusException se) {
logHandler().logStatus(se);
}

public static void logInternalError(Throwable throwable) {
logError("Internal Error!", throwable);
}

/** Logs an error status with given message. */
public static void logError(String message) {
logError(message, null);
}
/** Logs an error status with given message and given throwable. */
public static void logError(String message, Throwable throwable) {
logStatusException(new StatusException(Severity.ERROR, message, throwable));
}

/** Logs a warning status with given message. */
public static void logWarning(String message) {
logWarning(message, null);
}
/** Logs a warning status with given message and given throwable. */
public static void logWarning(String message, Throwable throwable) {
logStatusException(new StatusException(Severity.WARNING, message, throwable));
}

/** Logs an info status with given message. */
public static void logInfo(String message) {
logStatusException(new StatusException(Severity.INFO, message, null));
}

} }
Expand Up @@ -67,7 +67,7 @@ public void addProcessListener(IProcessOutputListener listener) throws CommonExc
}); });


try { try {
return new ExternalProcessNotifyingHelper(process, true, pm, processListeners, LangCore.logHandler()); return new ExternalProcessNotifyingHelper(process, true, pm, processListeners, LangCore.log());
} finally { } finally {
processListeners = null; // Set to null to fail fast if anyone else tries to modify afterward. processListeners = null; // Set to null to fail fast if anyone else tries to modify afterward.
} }
Expand Down
24 changes: 24 additions & 0 deletions plugin_tooling/src-util/melnorme/utilbox/misc/ILogHandler.java
Expand Up @@ -10,11 +10,35 @@
*******************************************************************************/ *******************************************************************************/
package melnorme.utilbox.misc; package melnorme.utilbox.misc;


import melnorme.utilbox.status.Severity;
import melnorme.utilbox.status.StatusException; import melnorme.utilbox.status.StatusException;




public interface ILogHandler { public interface ILogHandler {


void logStatus(StatusException statusException); void logStatus(StatusException statusException);


/** Logs an error status with given message. */
default void logError(String message) {
logError(message, null);
}
/** Logs an error status with given message and given throwable. */
default void logError(String message, Throwable throwable) {
logStatus(new StatusException(Severity.ERROR, message, throwable));
}

/** Logs a warning status with given message. */
default void logWarning(String message) {
logWarning(message, null);
}
/** Logs a warning status with given message and given throwable. */
default void logWarning(String message, Throwable throwable) {
logStatus(new StatusException(Severity.WARNING, message, throwable));
}

/** Logs an info status with given message. */
default void logInfo(String message) {
logStatus(new StatusException(Severity.INFO, message, null));
}

} }

0 comments on commit d422404

Please sign in to comment.