Skip to content

Commit

Permalink
old-repo OperationLogger moved to repo-sqlbase, can be reused as-is
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed May 18, 2021
1 parent 4d3c584 commit f707ddc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Expand Up @@ -19,6 +19,7 @@
import javax.annotation.PreDestroy;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.repo.sqlbase.OperationLogger;
import com.evolveum.midpoint.util.annotation.Experimental;

import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -413,7 +414,6 @@ public <T extends ObjectType> String addObject(
int attempt = 1;
int restarts = 0;
try {
// TODO use executeAttempts
final String operation = "adding";

String proposedOid = object.getOid();
Expand Down Expand Up @@ -703,7 +703,7 @@ public <T extends ObjectType> ModifyObjectResult<T> modifyObjectDynamically(
pm.registerOperationFinish(opHandle, attempt);
throw t;
} finally {
OperationLogger.logModifyDynamically(type, oid, rv, getOptions, modifyOptions, result);
OperationLogger.logModifyDynamically(type, oid, rv, modifyOptions, result);
}
}

Expand Down
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2018 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sql;
package com.evolveum.midpoint.repo.sqlbase;

import java.util.Collection;

Expand All @@ -23,10 +23,6 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
* @author semancik
*
*/
public class OperationLogger {

private static final Trace LOGGER_OP = TraceManager.getTrace("com.evolveum.midpoint.repo.operation");
Expand All @@ -40,25 +36,36 @@ public static <O extends ObjectType> void logAdd(PrismObject<O> object, RepoAddO
object.debugDump(1));
}

public static <O extends ObjectType> void logModify(Class<O> type, String oid, Collection<? extends ItemDelta> modifications,
ModificationPrecondition<O> precondition, RepoModifyOptions options, OperationResult subResult) {
public static <O extends ObjectType> void logModify(
Class<O> type,
String oid,
Collection<? extends ItemDelta<?, ?>> modifications,
ModificationPrecondition<O> precondition,
RepoModifyOptions options,
OperationResult subResult) {
if (!LOGGER_OP.isDebugEnabled()) {
return;
}
LOGGER_OP.debug("{} modify {} {}{}{}: {}\n{}", PREFIX, type.getSimpleName(), oid,
shortDumpOptions(options),
precondition == null ? "" : " precondition="+precondition+", ",
precondition == null ? "" : " precondition=" + precondition + ", ",
getStatus(subResult),
DebugUtil.debugDump(modifications, 1, false));
}

public static <O extends ObjectType> void logModifyDynamically(Class<O> type, String oid,
ModifyObjectResult<?> modifyObjectResult, Collection<SelectorOptions<GetOperationOptions>> getOptions,
RepoModifyOptions modifyOptions, OperationResult result) {
public static <O extends ObjectType> void logModifyDynamically(
Class<O> type,
String oid,
ModifyObjectResult<?> modifyObjectResult,
RepoModifyOptions modifyOptions,
OperationResult result) {
if (!LOGGER_OP.isDebugEnabled()) {
return;
}
Collection<? extends ItemDelta> modifications = modifyObjectResult != null ? modifyObjectResult.getModifications() : null;
Collection<? extends ItemDelta<?, ?>> modifications =
modifyObjectResult != null
? modifyObjectResult.getModifications()
: null;
LOGGER_OP.debug("{} modify dynamically {} {}{}: {}\n{}", PREFIX, type.getSimpleName(), oid,
shortDumpOptions(modifyOptions),
getStatus(result),
Expand Down Expand Up @@ -86,7 +93,7 @@ private static Object shortDumpOptions(ShortDumpable options) {
if (options == null) {
return "";
} else {
return " ["+options.shortDump()+"]";
return " [" + options.shortDump() + "]";
}
}

Expand All @@ -111,5 +118,4 @@ private static String getStatus(OperationResult subResult) {
return subResult.getStatus().toString() + ": " + message;
}
}

}

0 comments on commit f707ddc

Please sign in to comment.