mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
improve logging
This commit is contained in:
@@ -35,6 +35,9 @@ package sonia.scm.client;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.util.ServiceUtil;
|
||||
|
||||
/**
|
||||
@@ -47,6 +50,9 @@ public class ScmClient
|
||||
/** Field description */
|
||||
private static volatile ScmClientProvider provider = null;
|
||||
|
||||
/** the logger for ScmClient */
|
||||
private static final Logger logger = LoggerFactory.getLogger(ScmClient.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -91,8 +97,10 @@ public class ScmClient
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws ScmClientException
|
||||
*/
|
||||
private static ScmClientProvider getProvider()
|
||||
private static ScmClientProvider getProvider() throws ScmClientException
|
||||
{
|
||||
if (provider == null)
|
||||
{
|
||||
@@ -105,6 +113,16 @@ public class ScmClient
|
||||
}
|
||||
}
|
||||
|
||||
if (provider == null)
|
||||
{
|
||||
throw new ScmClientException("could not find a ScmClientProvider");
|
||||
}
|
||||
else if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("create ScmClient with provider {}",
|
||||
provider.getClass().getName());
|
||||
}
|
||||
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
|
||||
package sonia.scm.client;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -52,6 +57,10 @@ public class ScmUrlProvider
|
||||
/** Field description */
|
||||
public static final String URLPART_REPOSITORY = "repositories/";
|
||||
|
||||
/** the logger for classVar */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(ScmUrlProvider.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -70,6 +79,11 @@ public class ScmUrlProvider
|
||||
{
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("create new url provider with baseurl {}", this.baseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -141,7 +155,14 @@ public class ScmUrlProvider
|
||||
*/
|
||||
public String getResourceUrl(String urlPart)
|
||||
{
|
||||
return baseUrl.concat(urlPart).concat(extension);
|
||||
String resourceUrl = baseUrl.concat(urlPart).concat(extension);
|
||||
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("return resourceurl {}", resourceUrl);
|
||||
}
|
||||
|
||||
return resourceUrl;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
@@ -35,6 +35,9 @@ package sonia.scm.client;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig;
|
||||
|
||||
import sonia.scm.ScmState;
|
||||
@@ -58,6 +61,12 @@ import javax.ws.rs.core.MultivaluedMap;
|
||||
public class JerseyClientProvider implements ScmClientProvider
|
||||
{
|
||||
|
||||
/** the logger for JerseyClientProvider */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(JerseyClientProvider.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -71,12 +80,24 @@ public class JerseyClientProvider implements ScmClientProvider
|
||||
* @throws ScmClientException
|
||||
*/
|
||||
@Override
|
||||
public ScmClientSession createSession(String url, String username,
|
||||
public JerseyClientSession createSession(String url, String username,
|
||||
String password)
|
||||
throws ScmClientException
|
||||
{
|
||||
AssertUtil.assertIsNotEmpty(url);
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
String user = "anonymous";
|
||||
|
||||
if (Util.isNotEmpty(username))
|
||||
{
|
||||
user = username;
|
||||
}
|
||||
|
||||
logger.info("create new session for {} with username {}", url, user);
|
||||
}
|
||||
|
||||
ScmUrlProvider urlProvider = new ScmUrlProvider(url);
|
||||
DefaultAhcConfig config = new DefaultAhcConfig();
|
||||
Client client = Client.create(config);
|
||||
@@ -85,6 +106,11 @@ public class JerseyClientProvider implements ScmClientProvider
|
||||
|
||||
if (Util.isNotEmpty(username) && Util.isNotEmpty(password))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("try login for {}", username);
|
||||
}
|
||||
|
||||
MultivaluedMap<String, String> formData = new MultivaluedMapImpl();
|
||||
|
||||
formData.add("username", username);
|
||||
@@ -94,11 +120,21 @@ public class JerseyClientProvider implements ScmClientProvider
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("try anonymous login");
|
||||
}
|
||||
|
||||
response = resource.get(ClientResponse.class);
|
||||
}
|
||||
|
||||
if (response.getStatus() == 401)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("server returned 401 unauthorized");
|
||||
}
|
||||
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
@@ -106,6 +142,11 @@ public class JerseyClientProvider implements ScmClientProvider
|
||||
|
||||
if (!state.isSuccess())
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("server returned state failed");
|
||||
}
|
||||
|
||||
throw new ScmClientException("create ScmClientSession failed");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@ package sonia.scm.client;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.ScmState;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.repository.Repository;
|
||||
@@ -53,6 +56,12 @@ import java.io.IOException;
|
||||
public class JerseyClientSession implements ScmClientSession
|
||||
{
|
||||
|
||||
/** the logger for JerseyClientSession */
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(JerseyClientSession.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
@@ -80,6 +89,11 @@ public class JerseyClientSession implements ScmClientSession
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("close client session");
|
||||
}
|
||||
|
||||
client.destroy();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user