Skip to content

Commit 2f2b2de

Browse files
committed
make loggers non-static
1 parent 5860855 commit 2f2b2de

19 files changed

+93
-86
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/DebugSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.microsoft.java.debug.core.protocol.JsonUtils;
1919

2020
public final class DebugSettings {
21-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
21+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
2222
private static DebugSettings current = new DebugSettings();
2323

2424
public int maxStringLength = 0;

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/EventHub.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import io.reactivex.subjects.PublishSubject;
3232

3333
public class EventHub implements IEventHub {
34-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
34+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
3535
private PublishSubject<DebugEvent> subject = PublishSubject.<DebugEvent>create();
3636

3737
@Override

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/UsageDataSession.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import com.sun.jdi.event.Event;
2929

3030
public class UsageDataSession {
31-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
32-
private static final Logger usageDataLogger = Logger.getLogger(Configuration.USAGE_DATA_LOGGER_NAME);
31+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
32+
private final Logger usageDataLogger = Logger.getLogger(Configuration.USAGE_DATA_LOGGER_NAME);
3333
private static final long RESPONSE_MAX_DELAY_MS = 1000;
3434
private static final ThreadLocal<UsageDataSession> threadLocal = new InheritableThreadLocal<>();
3535

@@ -48,6 +48,10 @@ public static String getSessionGuid() {
4848
return threadLocal.get() == null ? "" : threadLocal.get().sessionGuid;
4949
}
5050

51+
public static UsageDataSession currentSession() {
52+
return threadLocal.get();
53+
}
54+
5155
public UsageDataSession() {
5256
threadLocal.set(this);
5357
}
@@ -153,16 +157,13 @@ public void submitUsageData() {
153157
/**
154158
* Record JDI event.
155159
*/
156-
public static void recordEvent(Event event) {
160+
public void recordEvent(Event event) {
157161
try {
158-
UsageDataSession currentSession = threadLocal.get();
159-
if (currentSession != null) {
160-
Map<String, String> eventEntry = new HashMap<>();
161-
eventEntry.put("timestamp", String.valueOf(System.currentTimeMillis()));
162-
eventEntry.put("event", event.toString());
163-
synchronized (currentSession.eventList) {
164-
currentSession.eventList.add(JsonUtils.toJson(eventEntry));
165-
}
162+
Map<String, String> eventEntry = new HashMap<>();
163+
eventEntry.put("timestamp", String.valueOf(System.currentTimeMillis()));
164+
eventEntry.put("event", event.toString());
165+
synchronized (eventList) {
166+
eventList.add(JsonUtils.toJson(eventEntry));
166167
}
167168
} catch (Exception e) {
168169
logger.log(Level.SEVERE, String.format("Exception on recording event: %s.", e.toString()), e);

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/BreakpointManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.microsoft.java.debug.core.IBreakpoint;
2525

2626
public class BreakpointManager {
27-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
27+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
2828
/**
2929
* A collection of breakpoints registered with this manager.
3030
*/

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/DebugAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import com.microsoft.java.debug.core.protocol.Requests.Command;
4848

4949
public class DebugAdapter implements IDebugAdapter {
50-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
50+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
5151

5252
private IDebugAdapterContext debugContext = null;
5353
private Map<Command, List<IDebugRequestHandler>> requestHandlersForDebug = null;

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/ProtocolServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.sun.jdi.VMDisconnectedException;
3030

3131
public class ProtocolServer extends AbstractProtocolServer {
32-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
32+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
3333

3434
private IDebugAdapter debugAdapter;
3535
private UsageDataSession usageDataSession = new UsageDataSession();

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/AbstractDisconnectRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.microsoft.java.debug.core.protocol.Requests.Command;
3030

3131
public abstract class AbstractDisconnectRequestHandler implements IDebugRequestHandler {
32-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
32+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
3333

3434
@Override
3535
public List<Command> getTargetCommands() {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Microsoft Corporation and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Microsoft Corporation - initial API and implementation
10+
*******************************************************************************/
11+
12+
package com.microsoft.java.debug.core.adapter.handler;
13+
14+
import com.microsoft.java.debug.core.Configuration;
15+
import com.microsoft.java.debug.core.protocol.Requests;
16+
17+
import java.util.ArrayList;
18+
import java.util.HashMap;
19+
import java.util.List;
20+
import java.util.Map;
21+
import java.util.logging.Logger;
22+
23+
abstract class AbstractLaunchDelegate implements ILaunchDelegate {
24+
protected final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
25+
26+
protected String[] constructEnvironmentVariables(Requests.LaunchArguments launchArguments) {
27+
String[] envVars = null;
28+
if (launchArguments.env != null && !launchArguments.env.isEmpty()) {
29+
Map<String, String> environment = new HashMap<>(System.getenv());
30+
List<String> duplicated = new ArrayList<>();
31+
for (Map.Entry<String, String> entry : launchArguments.env.entrySet()) {
32+
if (environment.containsKey(entry.getKey())) {
33+
duplicated.add(entry.getKey());
34+
}
35+
environment.put(entry.getKey(), entry.getValue());
36+
}
37+
// For duplicated variables, show a warning message.
38+
if (!duplicated.isEmpty()) {
39+
logger.warning(String.format("There are duplicated environment variables. The values specified in launch.json will be used. "
40+
+ "Here are the duplicated entries: %s.", String.join(",", duplicated)));
41+
}
42+
43+
envVars = new String[environment.size()];
44+
int i = 0;
45+
for (Map.Entry<String, String> entry : environment.entrySet()) {
46+
envVars[i++] = entry.getKey() + "=" + entry.getValue();
47+
}
48+
}
49+
return envVars;
50+
}
51+
}

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/AttachRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
4242

4343
public class AttachRequestHandler implements IDebugRequestHandler {
44-
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
44+
private final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
4545

4646
@Override
4747
public List<Command> getTargetCommands() {

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/ConfigurationDoneRequestHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import com.sun.jdi.event.VMStartEvent;
4343

4444
public class ConfigurationDoneRequestHandler implements IDebugRequestHandler {
45-
protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
45+
protected final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
4646

4747
@Override
4848
public List<Command> getTargetCommands() {
@@ -120,7 +120,10 @@ private void handleDebugEvent(DebugEvent debugEvent, IDebugSession debugSession,
120120

121121
// record events of important types only, to get rid of noises.
122122
if (isImportantEvent) {
123-
UsageDataSession.recordEvent(event);
123+
UsageDataSession session = UsageDataSession.currentSession();
124+
if (session != null) {
125+
session.recordEvent(event);
126+
}
124127
}
125128
}
126129
}

0 commit comments

Comments
 (0)