Skip to content

Commit

Permalink
append log type to each logger
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Nov 9, 2023
1 parent 624f7f4 commit 4bac0cb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class ActivityLogger {

private static String filename = "dotcms-userActivity.log";
private static String logType = "[Activity] ";

public static synchronized void logInfo(Class cl, String action, String msg) {
logInfo(cl, action, msg, null);
Expand All @@ -17,15 +18,15 @@ public static synchronized void logInfo(Class cl, String action, String msg) {
public static synchronized void logInfo(Class cl, String action,
String msg, String hostNameOrId) {
if (LogMapper.getInstance().isLogEnabled(filename)) {
Logger.info(ActivityLogger.class, cl.toString() + ": " + getHostName(hostNameOrId)
Logger.info(ActivityLogger.class, logType + cl.toString() + ": " + getHostName(hostNameOrId)
+ " : " + action + " , " + msg);
}
}

public static void logDebug(Class cl, String action, String msg, String hostNameOrId) {

if (LogMapper.getInstance().isLogEnabled(filename)) {
Logger.debug(ActivityLogger.class, cl.toString() + ": " + getHostName(hostNameOrId)
Logger.debug(ActivityLogger.class, logType + cl.toString() + ": " + getHostName(hostNameOrId)
+ " :" + action + " , " + msg);
}
}
Expand Down
9 changes: 5 additions & 4 deletions dotCMS/src/main/java/com/dotmarketing/util/AdminLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
public class AdminLogger {

private static String filename = "dotcms-adminaudit.log";
private static String logType = "[Admin Audit] ";

public static void log ( Class cl, String methodName, String msg ) {

if ( LogMapper.getInstance().isLogEnabled( filename ) ) {
Logger.info( cl, methodName + " : " + msg );
Logger.info( AdminLogger.class, cl.toString() + " : " + methodName + " : " + msg );
Logger.info( cl, logType + methodName + " : " + msg );
Logger.info( AdminLogger.class, logType + cl.toString() + " : " + methodName + " : " + msg );
}
}

Expand All @@ -25,8 +26,8 @@ public static void log ( Class cl, String methodName, String msg, User user ) {
log( cl, methodName, msg );
} else {
if ( LogMapper.getInstance().isLogEnabled( filename ) ) {
Logger.info( cl, "UserId : " + user.getUserId() + " : " + methodName + " : " + msg );
Logger.info( AdminLogger.class, "UserId : " + user.getUserId() + " : " + cl.toString() + " : " + methodName + " : " + msg );
Logger.info( cl, logType + "UserId : " + user.getUserId() + " : " + methodName + " : " + msg );
Logger.info( AdminLogger.class, logType + "UserId : " + user.getUserId() + " : " + cl.toString() + " : " + methodName + " : " + msg );
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions dotCMS/src/main/java/com/dotmarketing/util/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Logger{
Log4jUtil.configureDefaultSystemProperties();
}
private static WeakHashMap<Class, org.apache.logging.log4j.Logger> map = new WeakHashMap<>();
private static String velocityLogType = "[Velocity] ";

public static void clearLoggers(){
map.clear();
Expand Down Expand Up @@ -307,75 +308,75 @@ public static void velocityError(Class cl, String message, Throwable thr){
if(logger == null){
logger = loadLogger(cl);
}
logger.error(message + " @ " + Thread.currentThread().getName(), thr);
logger.error(velocityLogType + message + " @ " + Thread.currentThread().getName(), thr);
}

public static void velocityWarn(Class cl, String message, Throwable thr){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.warn(message + " @ " + Thread.currentThread().getName(), thr);
logger.warn(velocityLogType + message + " @ " + Thread.currentThread().getName(), thr);
}

public static void velocityInfo(Class cl, String message, Throwable thr){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.info(message + " @ " + Thread.currentThread().getName(), thr);
logger.info(velocityLogType + message + " @ " + Thread.currentThread().getName(), thr);
}
public static void velocityFatal(Class cl, String message, Throwable thr){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.fatal(message + " @ " + Thread.currentThread().getName(), thr);
logger.fatal(velocityLogType + message + " @ " + Thread.currentThread().getName(), thr);
}
public static void velocityDebug(Class cl, String message, Throwable thr){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.debug(message + " @ " + Thread.currentThread().getName(), thr);
logger.debug(velocityLogType + message + " @ " + Thread.currentThread().getName(), thr);
}

public static void velocityError(Class cl, String message){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.error(message + " @ " + Thread.currentThread().getName());
logger.error(velocityLogType + message + " @ " + Thread.currentThread().getName());
}

public static void velocityWarn(Class cl, String message){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.warn(message + " @ " + Thread.currentThread().getName());
logger.warn(velocityLogType + message + " @ " + Thread.currentThread().getName());
}

public static void velocityInfo(Class cl, String message){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.info(message + " @ " + Thread.currentThread().getName());
logger.info(velocityLogType + message + " @ " + Thread.currentThread().getName());
}
public static void velocityFatal(Class cl, String message){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.fatal(message + " @ " + Thread.currentThread().getName());
logger.fatal(velocityLogType + message + " @ " + Thread.currentThread().getName());
}
public static void velocityDebug(Class cl, String message){
org.apache.logging.log4j.Logger logger = map.get(cl);
if(logger == null){
logger = loadLogger(cl);
}
logger.debug(message + " @ " + Thread.currentThread().getName());
logger.debug(velocityLogType + message + " @ " + Thread.currentThread().getName());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class PushPublishLogger {

private static String filename = "dotcms-pushpublish.log";
private static String logType = "[PushPublish] ";

public enum PushPublishHandler {
CATEGORY("Category"),
Expand Down Expand Up @@ -62,15 +63,15 @@ public String toString() {
public static void log ( Class cl, String msg ) {

if ( LogMapper.getInstance().isLogEnabled( filename ) ) {
Logger.info( PushPublishLogger.class, cl.toString() + " : " + msg );
Logger.info( PushPublishLogger.class, logType + cl.toString() + " : " + msg );
}
}

@SuppressWarnings("rawtypes")
public static void log ( Class cl, String msg, String bundleId ) {

if ( LogMapper.getInstance().isLogEnabled( filename ) ) {
Logger.info( PushPublishLogger.class, cl.toString() + " : [BundleID: "+bundleId+"] " + msg );
Logger.info( PushPublishLogger.class, logType + cl.toString() + " : [BundleID: "+bundleId+"] " + msg );
}
}

Expand All @@ -81,15 +82,15 @@ public static void log ( Class cl, String msg, String bundleId, User user ) {
log( cl, msg , bundleId);
} else {
if ( LogMapper.getInstance().isLogEnabled( filename ) ) {
Logger.info( PushPublishLogger.class, cl.toString() + " : [BundleID: "+bundleId+"] " + msg + ", User: " + user.getUserId());
Logger.info( PushPublishLogger.class, logType + cl.toString() + " : [BundleID: "+bundleId+"] " + msg + ", User: " + user.getUserId());
}
}
}

public static void error ( final Class cl, final String msg, final String bundleId ) {

if ( LogMapper.getInstance().isLogEnabled( filename ) ) {
Logger.error( PushPublishLogger.class, cl.toString() + " : [BundleID: "+bundleId+"] " + msg );
Logger.error( PushPublishLogger.class, logType + cl.toString() + " : [BundleID: "+bundleId+"] " + msg );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class SecurityLogger {

private static String filename = "dotcms-security.log";
private static String logType = "[Security] ";

public static void logInfo(Class clazz, final Supplier<String> message) {
logInfo(clazz, message.get());
Expand All @@ -14,7 +15,7 @@ public static void logInfo(Class clazz, final Supplier<String> message) {
public static void logInfo(Class cl, String msg) {

if (LogMapper.getInstance().isLogEnabled(filename)) {
Logger.info(SecurityLogger.class, cl.toString() + " : " + msg);
Logger.info(SecurityLogger.class, logType + cl.toString() + " : " + msg);
}
}

Expand All @@ -25,7 +26,7 @@ public static void logDebug(Class clazz, final Supplier<String> message) {
public static void logDebug(Class cl, String msg) {

if (LogMapper.getInstance().isLogEnabled(filename)) {
Logger.debug(SecurityLogger.class, cl.toString() + " : " + msg);
Logger.debug(SecurityLogger.class, logType + cl.toString() + " : " + msg);
}
}

Expand Down

0 comments on commit 4bac0cb

Please sign in to comment.