KEYCLOAK-1280: i18n logging for org.keycloak.partialimport
This commit is contained in:
parent
273c662b29
commit
d2ad1808a5
3 changed files with 16 additions and 8 deletions
|
@ -21,11 +21,11 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.representations.idm.PartialImportRepresentation;
|
||||
import org.keycloak.services.ErrorResponse;
|
||||
import org.keycloak.services.ServicesLogger;
|
||||
|
||||
/**
|
||||
* Base PartialImport for most resource types.
|
||||
|
@ -33,7 +33,7 @@ import org.keycloak.services.ErrorResponse;
|
|||
* @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc.
|
||||
*/
|
||||
public abstract class AbstractPartialImport<T> implements PartialImport<T> {
|
||||
protected static Logger logger = Logger.getLogger(AbstractPartialImport.class);
|
||||
protected static ServicesLogger logger = ServicesLogger.ROOT_LOGGER;
|
||||
|
||||
protected final Set<T> toOverwrite = new HashSet<>();
|
||||
protected final Set<T> toSkip = new HashSet<>();
|
||||
|
@ -99,7 +99,7 @@ public abstract class AbstractPartialImport<T> implements PartialImport<T> {
|
|||
try {
|
||||
create(realm, session, resourceRep);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error overwriting " + getName(resourceRep), e);
|
||||
logger.overwriteError(e, getName(resourceRep));
|
||||
throw new ErrorResponseException(ErrorResponse.error(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ public abstract class AbstractPartialImport<T> implements PartialImport<T> {
|
|||
String modelId = getModelId(realm, session, resourceRep);
|
||||
results.addResult(added(modelId, resourceRep));
|
||||
} catch (Exception e) {
|
||||
logger.error("Error creating " + getName(resourceRep), e);
|
||||
logger.creationError(e, getName(resourceRep));
|
||||
throw new ErrorResponseException(ErrorResponse.error(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
@ -29,6 +28,7 @@ import org.keycloak.representations.idm.PartialImportRepresentation;
|
|||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
import org.keycloak.representations.idm.RolesRepresentation;
|
||||
import org.keycloak.services.ErrorResponse;
|
||||
import org.keycloak.services.ServicesLogger;
|
||||
|
||||
/**
|
||||
* This class handles both realm roles and client roles. It delegates to
|
||||
|
@ -44,7 +44,7 @@ import org.keycloak.services.ErrorResponse;
|
|||
* @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc.
|
||||
*/
|
||||
public class RolesPartialImport implements PartialImport<RolesRepresentation> {
|
||||
protected static Logger logger = Logger.getLogger(RolesPartialImport.class);
|
||||
protected static ServicesLogger logger = ServicesLogger.ROOT_LOGGER;
|
||||
|
||||
private Set<RoleRepresentation> realmRolesToOverwrite;
|
||||
private Set<RoleRepresentation> realmRolesToSkip;
|
||||
|
@ -97,7 +97,7 @@ public class RolesPartialImport implements PartialImport<RolesRepresentation> {
|
|||
try {
|
||||
RepresentationToModel.importRoles(rep.getRoles(), realm);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error importing roles", e);
|
||||
logger.roleImportError(e);
|
||||
throw new ErrorResponseException(ErrorResponse.error(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,15 @@ public interface ServicesLogger extends BasicLogger {
|
|||
@Message(id=35, value="Export finished successfully")
|
||||
void exportSuccess();
|
||||
|
||||
|
||||
@LogMessage(level = ERROR)
|
||||
@Message(id=36, value="Error overwriting %s")
|
||||
void overwriteError(@Cause Exception e, String name);
|
||||
|
||||
@LogMessage(level = ERROR)
|
||||
@Message(id=37, value="Error creating %s")
|
||||
void creationError(@Cause Exception e, String name);
|
||||
|
||||
@LogMessage(level = ERROR)
|
||||
@Message(id=38, value="Error importing roles")
|
||||
void roleImportError(@Cause Exception e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue