Skip to content
Snippets Groups Projects

Iss #70 - Add logging helper to the common lib

2 files
+ 41
1
Compare changes
  • Side-by-side
  • Inline
Files
2
/**
* Copyright (c) 2023 Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.core.helper;
/**
* Helpers for use in formatting log messages.
*
* @author Martin Lowe
*/
public final class LoggingHelper {
/**
* Formats the message part to remove newline characters. This is meant to be used for user-defined fields to prevent
* logging injections.
*
* @param msg the message part to format
* @return the sanitized log part.
*/
public static String format(String msg) {
if (msg == null) {
return "";
}
return msg.replaceAll("[\\n\\r]", "__");
}
private LoggingHelper() {
}
}
Loading