-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecure_Logger
More file actions
29 lines (24 loc) · 1016 Bytes
/
Secure_Logger
File metadata and controls
29 lines (24 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class SecureLogger {
private static final Logger logger = LoggerFactory.getLogger(SecureLogger.class);
private static final Pattern SENSITIVE_DATA =
Pattern.compile("\\b(password|credit_card|ssn)\\b",
Pattern.CASE_INSENSITIVE);
public static void logInfo(String message) {
logger.info(sanitizeLog(message));
}
public static void logError(String message, Throwable error) {
logger.error(sanitizeLog(message), error);
}
private static String sanitizeLog(String message) {
if (message == null) return null;
return SENSITIVE_DATA.matcher(message).replaceAll("[REDACTED]");
}
public static void auditLog(String userId, String action, String resource) {
String logMessage = String.format(
"User: %s, Action: %s, Resource: %s, Time: %s, IP: %s",
userId, action, resource,
LocalDateTime.now(), getCurrentIP()
);
logger.info("AUDIT: " + logMessage);
}
}