Skip to content

Commit

Permalink
remove String.format in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcheng15 committed Sep 5, 2022
1 parent 7a3165a commit 312557b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ object HttpClientCrawler {
} else null
} catch {
case e: Exception =>
if (log.isDebugEnabled()) {
log.debug(
String.format(
"request Error: %s\n url: %s",
e,
url
)
)
}
log.error(
"Request Error: {}\n url: {}",
e,
url
)
null
} finally {
if (response != null) {
Expand Down Expand Up @@ -121,17 +117,13 @@ object HttpClientCrawler {
params.keys.foreach(i => paramToString += String.format("{ %s, %s }", i, params(i)))
paramToString += "]"

if (log.isDebugEnabled()) {
log.debug(
String.format(
"requestByMethod Error: %s\n url: %s\n method: %s\n params: %s",
e,
url,
method,
paramToString
)
)
}
log.error(
"Error: {}\n url: {}\n method: {}\n params: {}",
e,
url,
method,
paramToString
)
null
} finally {
if (response != null) {
Expand All @@ -155,15 +147,11 @@ object HttpClientCrawler {
} else null
} catch {
case e: Exception =>
if (log.isDebugEnabled()) {
log.debug(
String.format(
"requestImage Error: %s\n url: %s",
e,
url
)
)
}
log.error(
"Error: {}\n url: {}",
e,
url
)
null
} finally {
if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class DefaultComparator extends Comparator with Logging{
def getExceptionStackAsString(exception: Exception): String = {
val sw = new StringWriter()
val pw = new PrintWriter(sw)
if (log.isDebugEnabled()) {
log.debug(String.format("Error: %s\n PrintWriter: %s", exception, pw.toString))
}
log.error("Error: {}\n PrintWriter: {}", exception, pw.toString)
sw.toString
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,11 @@ class SQLDownloadExt(override val uid: String) extends SQLAlg with DslTool with
}
catch {
case e: Exception =>
if (log.isDebugEnabled()) {
log.debug(
String.format(
"urlencode Error: %s\n getUrl: %s",
e,
getUrl
)
)
}
log.error(
"Error: {}\n getUrl: {}",
e,
getUrl
)
}
finally {
if( tarIS != null ) tarIS.close()
Expand Down
19 changes: 8 additions & 11 deletions streamingpro-mlsql/src/main/java/tech/mlsql/tool/TarfileUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tech.mlsql.tool;

import net.csdn.common.logging.CSLogger;
import net.csdn.common.logging.Loggers;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.Logger;
import org.kamranzafar.jtar.TarEntry;
import org.kamranzafar.jtar.TarInputStream;
import org.kamranzafar.jtar.TarOutputStream;
Expand All @@ -19,7 +20,7 @@
* 24/5/2021 WilliamZhu(allwefantasy@gmail.com)
*/
public class TarfileUtil {
private static Logger logger = Logger.getLogger(TarfileUtil.class);
private static CSLogger logger = Loggers.getLogger(TarfileUtil.class);

public static void walk(FileSystem fs, List<FileStatus> files, Path p) throws IOException {
if (fs.isFile(p)) {
Expand Down Expand Up @@ -87,15 +88,11 @@ public static int createTarFileStream(OutputStream output, String pathStr) throw
} else return 400;

} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(
String.format(
"createTarFileStream Error!!!\n pathStr: %s \n exception: %s",
pathStr,
e
)
);
}
logger.error(
"Error!!!\n pathStr: {} \n exception: {}",
pathStr,
e
);
return 500;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package streaming.core;

import net.csdn.common.logging.CSLogger;
import net.csdn.common.logging.Loggers;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.Logger;
import org.kamranzafar.jtar.TarOutputStream;

import javax.servlet.http.HttpServletResponse;
Expand All @@ -38,7 +39,7 @@
*/
public class DownloadRunner {

private static Logger logger = Logger.getLogger(DownloadRunner.class);
private static CSLogger logger = Loggers.getLogger(DownloadRunner.class);

public static int createTarFileStream(OutputStream output, String pathStr) {
String[] paths = pathStr.split(",");
Expand Down Expand Up @@ -89,9 +90,7 @@ public static int createTarFileStream(OutputStream output, String pathStr) {
} else return 400;

} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("createTarFileStream Error!!!\n pathStr: %s \n exception: %s", pathStr, e));
}
logger.error("Error!!!\n pathStr: {} \n exception: {}", pathStr, e);
return 500;

}
Expand All @@ -101,9 +100,7 @@ public static int getTarFileByPath(HttpServletResponse res, String pathStr) {
try {
return createTarFileStream(res.getOutputStream(), pathStr);
} catch (IOException e) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("getTarFileByPath Error!!!\n res: %s \n pathStr: %s \n exception: %s", res, pathStr, e));
}
logger.error("Error!!!\n res: {} \n pathStr: {} \n exception: {}", res, pathStr, e);
return 500;
}
}
Expand Down Expand Up @@ -182,9 +179,7 @@ public static int getRawFileByPath(HttpServletResponse res, String path, long po


} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("getRawFileByPath Error!!!\n res: %s \n path: %s \n position: %s \n exception: %s", res, path, position, e));
}
logger.error("Error!!!\n res: {} \n path: {} \n position: {} \n exception: {}", res, path, position, e);
}

return 500;
Expand Down

0 comments on commit 312557b

Please sign in to comment.