Skip to content

Commit fac7597

Browse files
committed
[GR-29900] Implement context bound logger
PullRequest: truffleruby/2483
2 parents 1a40956 + febe87e commit fac7597

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

mx.truffleruby/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "regex",
99
"subdir": True,
10-
"version": "eb1d9e5a58e016d3284e2df06ca65446b37b61c0",
10+
"version": "4df0f40cf23670bcc329b0e1b09a96089ee0d2e8",
1111
"urls": [
1212
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1313
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -16,7 +16,7 @@
1616
{
1717
"name": "sulong",
1818
"subdir": True,
19-
"version": "eb1d9e5a58e016d3284e2df06ca65446b37b61c0",
19+
"version": "4df0f40cf23670bcc329b0e1b09a96089ee0d2e8",
2020
"urls": [
2121
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2222
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},

src/main/java/org/truffleruby/RubyContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.oracle.truffle.api.CompilerAsserts;
2828
import com.oracle.truffle.api.CompilerDirectives;
2929
import com.oracle.truffle.api.RootCallTarget;
30+
import com.oracle.truffle.api.TruffleLogger;
3031
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
3132
import com.oracle.truffle.api.nodes.Node;
3233
import com.oracle.truffle.api.utilities.AssumedValue;
@@ -103,6 +104,7 @@ public class RubyContext {
103104
@CompilationFinal private PrintStream errStream;
104105
@CompilationFinal private boolean hasOtherPublicLanguages;
105106

107+
@CompilationFinal public TruffleLogger logger;
106108
@CompilationFinal private Options options;
107109
@CompilationFinal private String rubyHome;
108110
@CompilationFinal private TruffleFile rubyHomeTruffleFile;
@@ -159,6 +161,7 @@ public class RubyContext {
159161
public RubyContext(RubyLanguage language, TruffleLanguage.Env env) {
160162
Metrics.printTime("before-context-constructor");
161163

164+
this.logger = env.getLogger("");
162165
this.language = language;
163166
setEnv(env);
164167
this.preInitialized = preInitializing;
@@ -679,6 +682,10 @@ public PreInitializationManager getPreInitializationManager() {
679682
return preInitializationManager;
680683
}
681684

685+
public TruffleLogger getLogger() {
686+
return logger;
687+
}
688+
682689
public String getRubyHome() {
683690
return rubyHome;
684691
}

src/main/java/org/truffleruby/core/thread/ThreadNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ private static UnblockingAction makeUnblockingAction(RubyContext context, Object
591591
prev = truffleContext.enter(null);
592592
} catch (IllegalStateException e) { // Multi threaded access denied from Truffle
593593
// Not in a context, so we cannot use TruffleLogger
594-
context.getEnvErrStream().println(
595-
"[ruby] SEVERE: could not unblock thread inside blocking call in C extension because " +
594+
context.getLogger().severe(
595+
"could not unblock thread inside blocking call in C extension because " +
596596
"the context does not allow multithreading (" + e.getMessage() + ")");
597597
return;
598598
}

src/main/java/org/truffleruby/language/SafepointManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ private void driveArrivalAtPhaser(String reason) {
198198
} catch (TimeoutException e) {
199199
if (System.nanoTime() >= max) {
200200
// Possibly not in a context, so we cannot use TruffleLogger
201-
context.getEnvErrStream().println(String.format(
202-
"[ruby] SEVERE: waited %d seconds in the SafepointManager but %d of %d threads did not arrive - a thread is likely making a blocking call - reason for the safepoint: %s",
201+
context.getLogger().severe(String.format(
202+
"waited %d seconds in the SafepointManager but %d of %d threads did not arrive - a thread is likely making a blocking call - reason for the safepoint: %s",
203203
waits * WAIT_TIME_IN_SECONDS,
204204
phaser.getUnarrivedParties(),
205205
phaser.getRegisteredParties(),
@@ -209,8 +209,8 @@ private void driveArrivalAtPhaser(String reason) {
209209
restoreDefaultInterruptHandler();
210210
}
211211
if (max >= exitTime) {
212-
context.getEnvErrStream().println(
213-
"[ruby] SEVERE: waited " + MAX_WAIT_TIME_IN_SECONDS +
212+
context.getLogger().severe(
213+
"waited " + MAX_WAIT_TIME_IN_SECONDS +
214214
" seconds in the SafepointManager, terminating the process as it is unlikely to get unstuck");
215215
System.exit(1);
216216
}
@@ -256,11 +256,11 @@ private void printStacktracesOfBlockedThreads() {
256256

257257
private void restoreDefaultInterruptHandler() {
258258
// Possibly not in a context, so we cannot use TruffleLogger
259-
context.getEnvErrStream().println("[ruby] WARNING: restoring default interrupt handler");
259+
context.getLogger().warning("restoring default interrupt handler");
260260
try {
261261
Signals.restoreDefaultHandler("INT");
262262
} catch (Throwable t) {
263-
context.getEnvErrStream().println("[ruby] WARNING: failed to restore default interrupt handler\n" + t);
263+
context.getLogger().warning("failed to restore default interrupt handler\n" + t);
264264
}
265265
}
266266

0 commit comments

Comments
 (0)