mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-24 13:03:46 +08:00
issue #23 添加日志输出功能,使用了slf4j
This commit is contained in:
12
pom.xml
12
pom.xml
@@ -42,9 +42,21 @@
|
|||||||
<downloadJavadocs>true</downloadJavadocs>
|
<downloadJavadocs>true</downloadJavadocs>
|
||||||
<downloadSources>true</downloadSources>
|
<downloadSources>true</downloadSources>
|
||||||
<httpclient.version>4.3.5</httpclient.version>
|
<httpclient.version>4.3.5</httpclient.version>
|
||||||
|
<slf4j.version>1.7.10</slf4j.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>fluent-hc</artifactId>
|
<artifactId>fluent-hc</artifactId>
|
||||||
|
@@ -1,12 +1,16 @@
|
|||||||
package me.chanjar.weixin.common.session;
|
package me.chanjar.weixin.common.session;
|
||||||
|
|
||||||
import me.chanjar.weixin.common.util.res.StringManager;
|
import me.chanjar.weixin.common.util.res.StringManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class SessionManagerImpl implements WxSessionManager, InternalSessionManager {
|
public class SessionManagerImpl implements WxSessionManager, InternalSessionManager {
|
||||||
|
|
||||||
|
protected final Logger log = LoggerFactory.getLogger(SessionManagerImpl.class);
|
||||||
|
|
||||||
protected static final StringManager sm =
|
protected static final StringManager sm =
|
||||||
StringManager.getManager(Constants.Package);
|
StringManager.getManager(Constants.Package);
|
||||||
|
|
||||||
@@ -226,7 +230,7 @@ public class SessionManagerImpl implements WxSessionManager, InternalSessionMana
|
|||||||
int expireHere = 0 ;
|
int expireHere = 0 ;
|
||||||
|
|
||||||
if(log.isDebugEnabled())
|
if(log.isDebugEnabled())
|
||||||
log.debug("Start expire sessions " + getName() + " at " + timeNow + " sessioncount " + sessions.length);
|
log.debug("Start expire sessions {} at {} sessioncount {}", getName(), timeNow, sessions.length);
|
||||||
for (int i = 0; i < sessions.length; i++) {
|
for (int i = 0; i < sessions.length; i++) {
|
||||||
if (sessions[i]!=null && !sessions[i].isValid()) {
|
if (sessions[i]!=null && !sessions[i].isValid()) {
|
||||||
expireHere++;
|
expireHere++;
|
||||||
@@ -234,7 +238,7 @@ public class SessionManagerImpl implements WxSessionManager, InternalSessionMana
|
|||||||
}
|
}
|
||||||
long timeEnd = System.currentTimeMillis();
|
long timeEnd = System.currentTimeMillis();
|
||||||
if(log.isDebugEnabled())
|
if(log.isDebugEnabled())
|
||||||
log.debug("End expire sessions " + getName() + " processingTime " + (timeEnd - timeNow) + " expired sessions: " + expireHere);
|
log.debug("End expire sessions {} processingTime {} expired sessions: {}", getName(), timeEnd - timeNow, expireHere);
|
||||||
processingTime += ( timeEnd - timeNow );
|
processingTime += ( timeEnd - timeNow );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,8 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
|
|||||||
import org.apache.http.impl.client.BasicResponseHandler;
|
import org.apache.http.impl.client.BasicResponseHandler;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -45,6 +47,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
public class WxCpServiceImpl implements WxCpService {
|
public class WxCpServiceImpl implements WxCpService {
|
||||||
|
|
||||||
|
protected final Logger log = LoggerFactory.getLogger(WxCpServiceImpl.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局的是否正在刷新access token的锁
|
* 全局的是否正在刷新access token的锁
|
||||||
*/
|
*/
|
||||||
@@ -380,7 +384,7 @@ public class WxCpServiceImpl implements WxCpService {
|
|||||||
if (error.getErrorCode() == -1) {
|
if (error.getErrorCode() == -1) {
|
||||||
int sleepMillis = retrySleepMillis * (1 << retryTimes);
|
int sleepMillis = retrySleepMillis * (1 << retryTimes);
|
||||||
try {
|
try {
|
||||||
System.out.println("微信系统繁忙," + sleepMillis + "ms后重试(第" + (retryTimes + 1) + "次)");
|
log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
|
||||||
Thread.sleep(sleepMillis);
|
Thread.sleep(sleepMillis);
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
|
@@ -31,6 +31,8 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
|
|||||||
import org.apache.http.impl.client.BasicResponseHandler;
|
import org.apache.http.impl.client.BasicResponseHandler;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -42,6 +44,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class WxMpServiceImpl implements WxMpService {
|
public class WxMpServiceImpl implements WxMpService {
|
||||||
|
|
||||||
|
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局的是否正在刷新access token的锁
|
* 全局的是否正在刷新access token的锁
|
||||||
*/
|
*/
|
||||||
@@ -462,7 +466,7 @@ public class WxMpServiceImpl implements WxMpService {
|
|||||||
if (error.getErrorCode() == -1) {
|
if (error.getErrorCode() == -1) {
|
||||||
int sleepMillis = retrySleepMillis * (1 << retryTimes);
|
int sleepMillis = retrySleepMillis * (1 << retryTimes);
|
||||||
try {
|
try {
|
||||||
System.out.println("微信系统繁忙," + sleepMillis + "ms后重试(第" + (retryTimes + 1) + "次)");
|
log.debug("微信系统繁忙,{}ms 后重试(第{}次)", sleepMillis, retryTimes + 1);
|
||||||
Thread.sleep(sleepMillis);
|
Thread.sleep(sleepMillis);
|
||||||
} catch (InterruptedException e1) {
|
} catch (InterruptedException e1) {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
|
Reference in New Issue
Block a user