From 32f09630e94bd189515984da2c51e892ad2baf55 Mon Sep 17 00:00:00 2001 From: Yoway Buorn Date: Fri, 21 Jan 2022 20:44:41 +0300 Subject: [PATCH 1/2] writes errors to stderr --- src/main/java/io/supertokens/output/Logging.java | 3 +++ src/test/java/io/supertokens/test/LoggingTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/supertokens/output/Logging.java b/src/main/java/io/supertokens/output/Logging.java index 3852e9ae6..8b7cc47e5 100644 --- a/src/main/java/io/supertokens/output/Logging.java +++ b/src/main/java/io/supertokens/output/Logging.java @@ -186,6 +186,9 @@ private Logger createLoggerForConsole(Main main, String name) { ConsoleAppender logConsoleAppender = new ConsoleAppender<>(); logConsoleAppender.setEncoder(ple); logConsoleAppender.setContext(lc); + if (name.startsWith("io.supertokens.Error")) { + logConsoleAppender.setTarget("System.err"); + } logConsoleAppender.start(); Logger logger = (Logger) LoggerFactory.getLogger(name); diff --git a/src/test/java/io/supertokens/test/LoggingTest.java b/src/test/java/io/supertokens/test/LoggingTest.java index 39fb17460..79b59d729 100644 --- a/src/test/java/io/supertokens/test/LoggingTest.java +++ b/src/test/java/io/supertokens/test/LoggingTest.java @@ -171,7 +171,7 @@ public void confirmLoggerClosed() throws Exception { } @Test - public void testStandardOutLoggingWithNullStr() throws Exception { + public void testStdoutStderrWithNullStr() throws Exception { String[] args = { "../" }; ByteArrayOutputStream stdOutput = new ByteArrayOutputStream(); ByteArrayOutputStream errorOutput = new ByteArrayOutputStream(); @@ -192,7 +192,7 @@ public void testStandardOutLoggingWithNullStr() throws Exception { Logging.error(process.getProcess(), "errTest-sdvjovnoasid", false); assertTrue(fileContainsString(stdOutput, "outTest-dfkn3knsakn")); - assertTrue(fileContainsString(stdOutput, "errTest-sdvjovnoasid")); + assertTrue(fileContainsString(errorOutput, "errTest-sdvjovnoasid")); } finally { process.kill(); @@ -204,7 +204,7 @@ public void testStandardOutLoggingWithNullStr() throws Exception { } @Test - public void testStandardOutLoggingWithNull() throws Exception { + public void testStdoutStderrWithNull() throws Exception { String[] args = { "../" }; ByteArrayOutputStream stdOutput = new ByteArrayOutputStream(); ByteArrayOutputStream errorOutput = new ByteArrayOutputStream(); @@ -225,7 +225,7 @@ public void testStandardOutLoggingWithNull() throws Exception { Logging.error(process.getProcess(), "errTest-sdvjovnoasid", false); assertTrue(fileContainsString(stdOutput, "outTest-dfkn3knsakn")); - assertTrue(fileContainsString(stdOutput, "errTest-sdvjovnoasid")); + assertTrue(fileContainsString(errorOutput, "errTest-sdvjovnoasid")); } finally { process.kill(); From a7b4d7c44bec7e805573214f35e8c5338608c998 Mon Sep 17 00:00:00 2001 From: Yoway Buorn Date: Fri, 21 Jan 2022 20:44:41 +0300 Subject: [PATCH 2/2] writes errors to stderr --- CHANGELOG.md | 6 ++++++ src/main/java/io/supertokens/output/Logging.java | 3 +++ src/test/java/io/supertokens/test/LoggingTest.java | 8 ++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d94405b0f..80074841d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] - 2022-01-22 + +### Fixes + +- Run as container, errors are merged into stdout (instead of going to stderr) + ## [3.8.0] - 2022-01-14 ### Added diff --git a/src/main/java/io/supertokens/output/Logging.java b/src/main/java/io/supertokens/output/Logging.java index 3852e9ae6..8b7cc47e5 100644 --- a/src/main/java/io/supertokens/output/Logging.java +++ b/src/main/java/io/supertokens/output/Logging.java @@ -186,6 +186,9 @@ private Logger createLoggerForConsole(Main main, String name) { ConsoleAppender logConsoleAppender = new ConsoleAppender<>(); logConsoleAppender.setEncoder(ple); logConsoleAppender.setContext(lc); + if (name.startsWith("io.supertokens.Error")) { + logConsoleAppender.setTarget("System.err"); + } logConsoleAppender.start(); Logger logger = (Logger) LoggerFactory.getLogger(name); diff --git a/src/test/java/io/supertokens/test/LoggingTest.java b/src/test/java/io/supertokens/test/LoggingTest.java index 39fb17460..79b59d729 100644 --- a/src/test/java/io/supertokens/test/LoggingTest.java +++ b/src/test/java/io/supertokens/test/LoggingTest.java @@ -171,7 +171,7 @@ public void confirmLoggerClosed() throws Exception { } @Test - public void testStandardOutLoggingWithNullStr() throws Exception { + public void testStdoutStderrWithNullStr() throws Exception { String[] args = { "../" }; ByteArrayOutputStream stdOutput = new ByteArrayOutputStream(); ByteArrayOutputStream errorOutput = new ByteArrayOutputStream(); @@ -192,7 +192,7 @@ public void testStandardOutLoggingWithNullStr() throws Exception { Logging.error(process.getProcess(), "errTest-sdvjovnoasid", false); assertTrue(fileContainsString(stdOutput, "outTest-dfkn3knsakn")); - assertTrue(fileContainsString(stdOutput, "errTest-sdvjovnoasid")); + assertTrue(fileContainsString(errorOutput, "errTest-sdvjovnoasid")); } finally { process.kill(); @@ -204,7 +204,7 @@ public void testStandardOutLoggingWithNullStr() throws Exception { } @Test - public void testStandardOutLoggingWithNull() throws Exception { + public void testStdoutStderrWithNull() throws Exception { String[] args = { "../" }; ByteArrayOutputStream stdOutput = new ByteArrayOutputStream(); ByteArrayOutputStream errorOutput = new ByteArrayOutputStream(); @@ -225,7 +225,7 @@ public void testStandardOutLoggingWithNull() throws Exception { Logging.error(process.getProcess(), "errTest-sdvjovnoasid", false); assertTrue(fileContainsString(stdOutput, "outTest-dfkn3knsakn")); - assertTrue(fileContainsString(stdOutput, "errTest-sdvjovnoasid")); + assertTrue(fileContainsString(errorOutput, "errTest-sdvjovnoasid")); } finally { process.kill();