From 1d837a835c04078ec66325e9fb9de21ac401874e Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Wed, 30 Nov 2016 15:10:15 +0700 Subject: prevent string concatenation for disabled loggers --- juick-api/src/main/java/com/juick/api/TGBot.java | 9 ++++++--- juick-api/src/main/java/com/juick/api/controllers/Post.java | 7 ++++--- .../src/main/java/com/juick/api/controllers/TelegramWebhook.java | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'juick-api/src/main') diff --git a/juick-api/src/main/java/com/juick/api/TGBot.java b/juick-api/src/main/java/com/juick/api/TGBot.java index e0ab3e1e..d532b02c 100644 --- a/juick-api/src/main/java/com/juick/api/TGBot.java +++ b/juick-api/src/main/java/com/juick/api/TGBot.java @@ -79,7 +79,10 @@ public class TGBot implements AutoCloseable { public void onTextMessage(WebSocket websocket, String text) throws Exception { super.onTextMessage(websocket, text); com.juick.Message jmsg = ms.readValue(text, com.juick.Message.class); - logger.info("got jmsg: " + ms.writeValueAsString(jmsg)); + + if (logger.isInfoEnabled()) // prevent writeValueAsString execution if logger disabled + logger.info("got jmsg: {}", ms.writeValueAsString(jmsg)); + String msgUrl = formatUrl(jmsg); if (jmsg.getRid() == 0) { String msg = formatPost(jmsg); @@ -118,7 +121,7 @@ public class TGBot implements AutoCloseable { bot.execute(telegramMessage, new Callback() { @Override public void onResponse(SendMessage request, SendResponse response) { - logger.info("got response: " + response.message().toString()); + logger.info("got response: {}", response.message()); } @Override @@ -140,7 +143,7 @@ public class TGBot implements AutoCloseable { })), new Callback() { @Override public void onResponse(SendMessage request, SendResponse response) { - logger.info("got response: " + response.message().toString()); + logger.info("got response: {}", response.message()); } @Override diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-api/src/main/java/com/juick/api/controllers/Post.java index 18f417d8..0fbf87e8 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/Post.java +++ b/juick-api/src/main/java/com/juick/api/controllers/Post.java @@ -99,7 +99,7 @@ public class Post { } String attachmentFName = HttpUtils.receiveMultiPartFile(attach, env.getProperty("upload_tmp_dir", - "/var/www/juick.com/i/tmp/")); + "/var/www/juick.com/i/tmp/")); if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) { try { @@ -142,7 +142,7 @@ public class Post { OobX xoob = new OobX(new URI(attachmentURL)); xmsg.addExtension(xoob); } catch (URISyntaxException e) { - logger.error("invalid uri: " + attachmentURL, e); + logger.error("invalid uri: {}, exception {}", attachmentURL, e); } } @@ -173,6 +173,7 @@ public class Post { } return jmsg; } + @RequestMapping(value = "/comment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public com.juick.Message doPostComment( Principal principal, @@ -263,7 +264,7 @@ public class Post { try { xmsg.addExtension(new OobX(new URI(attachmentURL))); } catch (URISyntaxException e) { - logger.error("invalid uri: " + attachmentURL, e); + logger.error("invalid uri: {}, exception {}", attachmentURL, e); } } diff --git a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java index 8b491167..60856ec6 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java +++ b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java @@ -38,13 +38,13 @@ public class TelegramWebhook { if (update.message() == null) { message = update.editedMessage(); if (message == null) { - logger.error("error parsing telegram update: " + update.toString()); + logger.error("error parsing telegram update: {}", update); return; } } - logger.info(String.format("got telegram msg %s", message.toString())); + logger.info("got telegram msg {}", message); User user_from = usersService.getUserByUID(telegramService.getUser(message.chat().id())).orElse(new User()); - logger.info(String.format("Found juick user %d", user_from.getUid())); + logger.info("Found juick user {}", user_from.getUid()); List chats = telegramService.getChats(); String username = message.from().username(); @@ -53,7 +53,7 @@ public class TelegramWebhook { } if (!chats.contains(message.chat().id())) { telegramService.addChat(message.chat().id()); - logger.info("added chat with " + username); + logger.info("added chat with {}", username); telegramService.createTelegramUser(message.from().id(), username); tgBot.telegramSignupNotify(message.from().id().longValue(), usersService.getSignUpHashByTelegramID(message.from().id().longValue(), username)); } else { -- cgit v1.2.3