Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOGMGR-347] Do not use deprecated SmallRye Common OS Process #464

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<description>An implementation of java.util.logging.LogManager</description>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager</artifactId>
<version>3.0.5.Final-SNAPSHOT</version>
<version>3.1.0.Final-SNAPSHOT</version>

<licenses>
<license>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jboss/logmanager/ExtLogRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

package org.jboss.logmanager;

import static java.security.AccessController.doPrivileged;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.UndeclaredThrowableException;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.Map;
import java.util.MissingResourceException;
Expand Down Expand Up @@ -108,7 +111,7 @@ public ExtLogRecord(final java.util.logging.Level level, final String msg, final
longThreadID = Thread.currentThread().getId(); // todo: threadId() on 19+
hostName = HostName.getQualifiedHostName();
processName = io.smallrye.common.os.Process.getProcessName();
processId = io.smallrye.common.os.Process.getProcessId();
processId = doPrivileged((PrivilegedAction<ProcessHandle>) ProcessHandle::current).pid();
}

/**
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/org/jboss/logmanager/handlers/SyslogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.jboss.logmanager.handlers;

import static java.security.AccessController.doPrivileged;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
Expand All @@ -34,6 +35,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.PrivilegedAction;
import java.text.Normalizer;
import java.text.Normalizer.Form;
import java.time.ZoneId;
Expand Down Expand Up @@ -346,7 +348,6 @@ public static enum SyslogType {
private String hostname;
private Facility facility;
private SyslogType syslogType;
private final String pid;
private OutputStream out;
private Protocol protocol;
private boolean useCountingFraming;
Expand Down Expand Up @@ -503,8 +504,6 @@ public SyslogHandler(final InetAddress serverAddress, final int port, final Faci
this.serverAddress = serverAddress;
this.port = port;
this.facility = facility;
final long pid = io.smallrye.common.os.Process.getProcessId();
this.pid = (pid != -1 ? Long.toString(pid) : null);
this.appName = "java";
this.hostname = checkPrintableAscii("host name", hostname);
this.syslogType = (syslogType == null ? SyslogType.RFC5424 : syslogType);
Expand Down Expand Up @@ -780,14 +779,11 @@ public void setEscapeEnabled(final boolean escapeEnabled) {
* Returns the pid being used as the PROCID for RFC5424 messages.
*
* @return the pid or {@code null} if the pid could not be determined
* @deprecated Always returns the current process ID, as a string.
*/
@Deprecated(forRemoval = true, since = "3.1")
dmlloyd marked this conversation as resolved.
Show resolved Hide resolved
public String getPid() {
lock.lock();
try {
return pid;
} finally {
lock.unlock();
}
return String.valueOf(doPrivileged((PrivilegedAction<ProcessHandle>) ProcessHandle::current).pid());
}

/**
Expand Down Expand Up @@ -1308,9 +1304,6 @@ protected byte[] createRFC5424Header(final ExtLogRecord record) throws IOExcepti
if (recordProcId != -1) {
buffer.append(recordProcId);
buffer.append(' ');
} else if (pid != null) {
buffer.appendPrintUSASCII(pid, 128);
buffer.append(' ');
} else {
buffer.appendUSASCII(NILVALUE_SP);
}
Expand Down Expand Up @@ -1381,9 +1374,6 @@ protected byte[] createRFC3164Header(final ExtLogRecord record) throws IOExcepti
if (recordProcId != -1) {
buffer.append('[').append(recordProcId).append(']');
colon = true;
} else if (pid != null) {
buffer.append('[').appendUSASCII(pid).append(']');
colon = true;
}
if (colon) {
buffer.append(':').append(' ');
Expand Down