Skip to content

Commit

Permalink
[Improvement-13491][*] Use lombok @slf4j annotation to generate logger
Browse files Browse the repository at this point in the history
  • Loading branch information
seedscoder committed Feb 7, 2023
1 parent 57db06e commit c882da7
Show file tree
Hide file tree
Showing 331 changed files with 2,839 additions and 3,293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,17 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* <p>
* https://open.dingtalk.com/document/robots/custom-robot-access
* https://open.dingtalk.com/document/robots/customize-robot-security-settings
* </p>
*/
@Slf4j
public final class DingTalkSender {

private static final Logger logger = LoggerFactory.getLogger(DingTalkSender.class);
private final String url;
private final String keyword;
private final String secret;
Expand Down Expand Up @@ -127,13 +126,13 @@ private AlertResult checkSendDingTalkSendMsgResult(String result) {

if (null == result) {
alertResult.setMessage("send ding talk msg error");
logger.info("send ding talk msg error,ding talk server resp is null");
log.info("send ding talk msg error,ding talk server resp is null");
return alertResult;
}
DingTalkSendMsgResponse sendMsgResponse = JSONUtils.parseObject(result, DingTalkSendMsgResponse.class);
if (null == sendMsgResponse) {
alertResult.setMessage("send ding talk msg fail");
logger.info("send ding talk msg error,resp error");
log.info("send ding talk msg error,resp error");
return alertResult;
}
if (sendMsgResponse.errcode == 0) {
Expand All @@ -142,7 +141,7 @@ private AlertResult checkSendDingTalkSendMsgResult(String result) {
return alertResult;
}
alertResult.setMessage(String.format("alert send ding talk msg error : %s", sendMsgResponse.getErrmsg()));
logger.info("alert send ding talk msg error : {}", sendMsgResponse.getErrmsg());
log.info("alert send ding talk msg error : {}", sendMsgResponse.getErrmsg());
return alertResult;
}

Expand All @@ -159,7 +158,7 @@ public AlertResult sendDingTalkMsg(String title, String content) {
String resp = sendMsg(title, content);
return checkSendDingTalkSendMsgResult(resp);
} catch (Exception e) {
logger.info("send ding talk alert msg exception : {}", e.getMessage());
log.info("send ding talk alert msg exception : {}", e.getMessage());
alertResult = new AlertResult();
alertResult.setStatus("false");
alertResult.setMessage("send ding talk alert fail.");
Expand Down Expand Up @@ -193,7 +192,7 @@ private String sendMsg(String title, String content) throws IOException {
} finally {
response.close();
}
logger.info("Ding Talk send msg :{}, resp: {}", msg, resp);
log.info("Ding Talk send msg :{}, resp: {}", msg, resp);
return resp;
} finally {
httpClient.close();
Expand Down Expand Up @@ -320,7 +319,7 @@ private String generateSignedUrl() {
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), "UTF-8");
} catch (Exception e) {
logger.error("generate sign error, message:{}", e);
log.error("generate sign error, message:{}", e);
}
return url + "&timestamp=" + timestamp + "&sign=" + sign;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class EmailAlertChannel implements AlertChannel {

private static final Logger logger = LoggerFactory.getLogger(EmailAlertChannel.class);

@Override
public AlertResult process(AlertInfo info) {

Expand All @@ -48,18 +46,18 @@ public AlertResult process(AlertInfo info) {
alertResult = new AlertResult();
alertResult.setStatus("false");
alertResult.setMessage("alert send error.");
logger.info("alert send error : {}", alertResult.getMessage());
log.info("alert send error : {}", alertResult.getMessage());
return alertResult;
}

flag = Boolean.parseBoolean(String.valueOf(alertResult.getStatus()));

if (flag) {
logger.info("alert send success");
log.info("alert send success");
alertResult.setMessage("email send success.");
} else {
alertResult.setMessage("alert send error.");
logger.info("alert send error : {}", alertResult.getMessage());
log.info("alert send error : {}", alertResult.getMessage());
}

return alertResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class ExcelUtils {

private static final int XLSX_WINDOW_ROW = 10000;
private static final Logger logger = LoggerFactory.getLogger(ExcelUtils.class);

private ExcelUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
Expand All @@ -57,14 +55,14 @@ private ExcelUtils() {
public static void genExcelFile(String content, String title, String xlsFilePath) {
File file = new File(xlsFilePath);
if (!file.exists() && !file.mkdirs()) {
logger.error("Create xlsx directory error, path:{}", xlsFilePath);
log.error("Create xlsx directory error, path:{}", xlsFilePath);
throw new AlertEmailException("Create xlsx directory error");
}

List<LinkedHashMap> itemsList = JSONUtils.toList(content, LinkedHashMap.class);

if (CollectionUtils.isEmpty(itemsList)) {
logger.error("itemsList is null");
log.error("itemsList is null");
throw new AlertEmailException("itemsList is null");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

import com.sun.mail.smtp.SMTPProvider;

@Slf4j
public final class MailSender {

private static final Logger logger = LoggerFactory.getLogger(MailSender.class);

private final List<String> receivers;
private final List<String> receiverCcs;
private final String mailProtocol = "SMTP";
Expand Down Expand Up @@ -390,20 +388,20 @@ private AlertResult getStringObjectMap(String title, String content, AlertResult
public void deleteFile(File file) {
if (file.exists()) {
if (file.delete()) {
logger.info("delete success: {}", file.getAbsolutePath());
log.info("delete success: {}", file.getAbsolutePath());
} else {
logger.info("delete fail: {}", file.getAbsolutePath());
log.info("delete fail: {}", file.getAbsolutePath());
}
} else {
logger.info("file not exists: {}", file.getAbsolutePath());
log.info("file not exists: {}", file.getAbsolutePath());
}
}

/**
* handle exception
*/
private void handleException(AlertResult alertResult, Exception e) {
logger.error("Send email to {} failed", receivers, e);
log.error("Send email to {} failed", receivers, e);
alertResult.setMessage("Send email to {" + String.join(",", receivers) + "} failed," + e.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.configurationprocessor.json.JSONArray;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.boot.configurationprocessor.json.JSONTokener;
Expand All @@ -42,10 +42,9 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

@Slf4j
public class DefaultHTMLTemplate implements AlertTemplate {

public static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplate.class);

@Override
public String getMessageFromTemplate(String content, ShowType showType, boolean showAll) {

Expand Down Expand Up @@ -128,7 +127,7 @@ private String getTextTypeMessage(String content) {
content = JSONUtils.toJsonString(Collections.singletonList(jsonNodes));
}
} catch (JSONException e) {
logger.error("alert content is null");
log.error("alert content is null");
}
ArrayNode list = JSONUtils.parseArray(content);
StringBuilder contents = new StringBuilder(100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@
import java.util.Map;
import java.util.Map.Entry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

import com.fasterxml.jackson.annotation.JsonProperty;

@Slf4j
public final class FeiShuSender {

private static final Logger logger = LoggerFactory.getLogger(FeiShuSender.class);
private final String url;
private final Boolean enableProxy;

Expand Down Expand Up @@ -84,14 +83,14 @@ public static AlertResult checkSendFeiShuSendMsgResult(String result) {

if (org.apache.commons.lang3.StringUtils.isBlank(result)) {
alertResult.setMessage("send fei shu msg error");
logger.info("send fei shu msg error,fei shu server resp is null");
log.info("send fei shu msg error,fei shu server resp is null");
return alertResult;
}
FeiShuSendMsgResponse sendMsgResponse = JSONUtils.parseObject(result, FeiShuSendMsgResponse.class);

if (null == sendMsgResponse) {
alertResult.setMessage("send fei shu msg fail");
logger.info("send fei shu msg error,resp error");
log.info("send fei shu msg error,resp error");
return alertResult;
}
if (sendMsgResponse.statusCode == 0) {
Expand All @@ -100,7 +99,7 @@ public static AlertResult checkSendFeiShuSendMsgResult(String result) {
return alertResult;
}
alertResult.setMessage(String.format("alert send fei shu msg error : %s", sendMsgResponse.getStatusMessage()));
logger.info("alert send fei shu msg error : {} ,Extra : {} ", sendMsgResponse.getStatusMessage(),
log.info("alert send fei shu msg error : {} ,Extra : {} ", sendMsgResponse.getStatusMessage(),
sendMsgResponse.getExtra());
return alertResult;
}
Expand Down Expand Up @@ -134,7 +133,7 @@ public AlertResult sendFeiShuMsg(AlertData alertData) {
String resp = sendMsg(alertData);
return checkSendFeiShuSendMsgResult(resp);
} catch (Exception e) {
logger.info("send fei shu alert msg exception : {}", e.getMessage());
log.info("send fei shu alert msg exception : {}", e.getMessage());
alertResult = new AlertResult();
alertResult.setStatus("false");
alertResult.setMessage("send fei shu alert fail.");
Expand All @@ -157,7 +156,7 @@ private String sendMsg(AlertData alertData) throws IOException {

int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
logger.error("send feishu message error, return http status code: {} ", statusCode);
log.error("send feishu message error, return http status code: {} ", statusCode);
}
String resp;
try {
Expand All @@ -167,7 +166,7 @@ private String sendMsg(AlertData alertData) throws IOException {
} finally {
response.close();
}
logger.info("Fei Shu send title :{} ,content :{}, resp: {}", alertData.getTitle(), alertData.getContent(),
log.info("Fei Shu send title :{} ,content :{}, resp: {}", alertData.getTitle(), alertData.getContent(),
resp);
return resp;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

import com.fasterxml.jackson.databind.node.ObjectNode;

@Slf4j
public final class HttpSender {

private static final Logger logger = LoggerFactory.getLogger(HttpSender.class);
private static final String URL_SPLICE_CHAR = "?";
/**
* request type post
Expand Down Expand Up @@ -96,7 +95,7 @@ public AlertResult send(String msg) {
alertResult.setStatus("true");
alertResult.setMessage(resp);
} catch (Exception e) {
logger.error("send http alert msg exception : {}", e.getMessage());
log.error("send http alert msg exception : {}", e.getMessage());
alertResult.setStatus("false");
alertResult.setMessage("send http request alert fail.");
}
Expand Down Expand Up @@ -170,7 +169,7 @@ private void setMsgInRequestBody(String msg) {
StringEntity entity = new StringEntity(JSONUtils.toJsonString(objectNode), DEFAULT_CHARSET);
((HttpPost) httpRequest).setEntity(entity);
} catch (Exception e) {
logger.error("send http alert msg exception : {}", e.getMessage());
log.error("send http alert msg exception : {}", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
import java.util.Map;
import java.util.Objects;

import org.slf4j.Logger;
import lombok.extern.slf4j.Slf4j;

import com.google.common.base.Preconditions;

@Slf4j
public final class PagerDutySender {

private static final Logger log = org.slf4j.LoggerFactory.getLogger(PagerDutySender.class);

private final String integrationKey;

public PagerDutySender(Map<String, String> config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class ProcessUtils {

private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class);

private ProcessUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
Expand All @@ -50,7 +48,7 @@ static Integer executeScript(String... cmd) {
errorStreamGobbler.start();
return process.waitFor();
} catch (IOException | InterruptedException e) {
logger.error("execute alert script error {}", e.getMessage());
log.error("execute alert script error {}", e.getMessage());
Thread.currentThread().interrupt();
}

Expand Down
Loading

0 comments on commit c882da7

Please sign in to comment.