summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/http/00_serve.ts6
-rw-r--r--runtime/js/99_main.js34
-rw-r--r--tests/integration/serve_tests.rs12
-rw-r--r--tests/integration/watcher_tests.rs6
-rw-r--r--tests/testdata/serve/parallel.ts4
-rw-r--r--tests/unit/serve_test.ts12
6 files changed, 30 insertions, 44 deletions
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts
index a49ab2790..87798656f 100644
--- a/ext/http/00_serve.ts
+++ b/ext/http/00_serve.ts
@@ -646,7 +646,7 @@ function serve(arg1, arg2) {
options.onListen(listener.addr);
} else {
// deno-lint-ignore no-console
- console.log(`Listening on ${path}`);
+ console.error(`Listening on ${path}`);
}
});
}
@@ -695,7 +695,7 @@ function serve(arg1, arg2) {
const host = formatHostName(addr.hostname);
// deno-lint-ignore no-console
- console.log(`Listening on ${scheme}${host}:${addr.port}/`);
+ console.error(`Listening on ${scheme}${host}:${addr.port}/`);
}
};
@@ -871,7 +871,7 @@ function registerDeclarativeServer(exports) {
const host = formatHostName(hostname);
// deno-lint-ignore no-console
- console.debug(
+ console.error(
`%cdeno serve%c: Listening on %chttp://${host}:${port}/%c${nThreads}`,
"color: green",
"color: inherit",
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index f447a9eef..aaf12a1c4 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -3,6 +3,7 @@
// Remove Intl.v8BreakIterator because it is a non-standard API.
delete Intl.v8BreakIterator;
+import * as internalConsole from "ext:deno_console/01_console.js";
import { core, internals, primordials } from "ext:core/mod.js";
const ops = core.ops;
import {
@@ -578,36 +579,19 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
if (mode === executionModes.serve) {
if (serveIsMain && serveWorkerCount) {
- // deno-lint-ignore no-console
- const origLog = console.log;
- // deno-lint-ignore no-console
- const origError = console.error;
- const prefix = `[serve-worker-0 ]`;
- // deno-lint-ignore no-console
- console.log = (...args) => {
- return origLog(prefix, ...new primordials.SafeArrayIterator(args));
- };
- // deno-lint-ignore no-console
- console.error = (...args) => {
- return origError(prefix, ...new primordials.SafeArrayIterator(args));
- };
+ // deno-lint-ignore no-global-assign
+ console = new internalConsole.Console((msg, level) =>
+ core.print("[serve-worker-0 ] " + msg, level > 1)
+ );
} else if (serveWorkerCount !== null) {
- // deno-lint-ignore no-console
- const origLog = console.log;
- // deno-lint-ignore no-console
- const origError = console.error;
const base = `serve-worker-${serveWorkerCount + 1}`;
// 15 = "serve-worker-nn".length, assuming
// serveWorkerCount < 100
const prefix = `[${StringPrototypePadEnd(base, 15, " ")}]`;
- // deno-lint-ignore no-console
- console.log = (...args) => {
- return origLog(prefix, ...new primordials.SafeArrayIterator(args));
- };
- // deno-lint-ignore no-console
- console.error = (...args) => {
- return origError(prefix, ...new primordials.SafeArrayIterator(args));
- };
+ // deno-lint-ignore no-global-assign
+ console = new internalConsole.Console((msg, level) =>
+ core.print(`${prefix} ` + msg, level > 1)
+ );
}
}
diff --git a/tests/integration/serve_tests.rs b/tests/integration/serve_tests.rs
index c34b0e286..a1df7825d 100644
--- a/tests/integration/serve_tests.rs
+++ b/tests/integration/serve_tests.rs
@@ -61,11 +61,13 @@ impl ServeClientBuilder {
fn new() -> Self {
Self(
util::deno_cmd()
+ .env("NO_COLOR", "1")
.current_dir(util::testdata_path())
.arg("serve")
.arg("--port")
.arg("0")
- .stdout_piped(),
+ .stdout_piped()
+ .stderr_piped(),
None,
)
}
@@ -106,12 +108,12 @@ impl ServeClient {
fn output(self) -> String {
let mut child = self.child.borrow_mut();
child.kill().unwrap();
- let mut stdout = child.stdout.take().unwrap();
+ let mut stderr = child.stderr.take().unwrap();
child.wait().unwrap();
let mut output_buf = self.output_buf.borrow_mut();
- stdout.read_to_end(&mut output_buf).unwrap();
+ stderr.read_to_end(&mut output_buf).unwrap();
String::from_utf8(std::mem::take(&mut *output_buf)).unwrap()
}
@@ -128,7 +130,7 @@ impl ServeClient {
let mut buffer = self.output_buf.borrow_mut();
let mut temp_buf = [0u8; 64];
let mut child = self.child.borrow_mut();
- let stdout = child.stdout.as_mut().unwrap();
+ let stderr = child.stderr.as_mut().unwrap();
let port_regex = regex::bytes::Regex::new(r":(\d+)").unwrap();
let start = std::time::Instant::now();
@@ -141,7 +143,7 @@ impl ServeClient {
String::from_utf8_lossy(&buffer)
);
}
- let read = stdout.read(&mut temp_buf).unwrap();
+ let read = stderr.read(&mut temp_buf).unwrap();
buffer.extend_from_slice(&temp_buf[..read]);
if let Some(p) = port_regex
.captures(&buffer)
diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs
index 2590e79d6..27c59a27d 100644
--- a/tests/integration/watcher_tests.rs
+++ b/tests/integration/watcher_tests.rs
@@ -1359,16 +1359,16 @@ async fn test_watch_serve() {
.piped_output()
.spawn()
.unwrap();
- let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
+ let (mut _stdout_lines, mut stderr_lines) = child_lines(&mut child);
- wait_contains("Listening on", &mut stdout_lines).await;
+ wait_contains("Listening on", &mut stderr_lines).await;
// Note that we start serving very quickly, so we specifically want to wait for this message
wait_contains(r#"Watching paths: [""#, &mut stderr_lines).await;
file_to_watch.write(file_content);
wait_contains("serving", &mut stderr_lines).await;
- wait_contains("Listening on", &mut stdout_lines).await;
+ wait_contains("Listening on", &mut stderr_lines).await;
check_alive_then_kill(child);
}
diff --git a/tests/testdata/serve/parallel.ts b/tests/testdata/serve/parallel.ts
index f1f118c71..2ba7ccfca 100644
--- a/tests/testdata/serve/parallel.ts
+++ b/tests/testdata/serve/parallel.ts
@@ -1,7 +1,7 @@
-console.log("starting serve");
+console.error("starting serve");
export default {
fetch(_req: Request) {
- console.log("serving request");
+ console.error("serving request");
return new Response("deno serve parallel");
},
};
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts
index 4a19d8df2..c1e217a11 100644
--- a/tests/unit/serve_test.ts
+++ b/tests/unit/serve_test.ts
@@ -792,8 +792,8 @@ Deno.test(
async function httpServerDefaultOnListenCallback() {
const ac = new AbortController();
- const consoleLog = console.log;
- console.log = (msg) => {
+ const consoleError = console.error;
+ console.error = (msg) => {
try {
const match = msg.match(
/Listening on http:\/\/(localhost|0\.0\.0\.0):(\d+)\//,
@@ -818,7 +818,7 @@ Deno.test(
await server.finished;
} finally {
- console.log = consoleLog;
+ console.error = consoleError;
}
},
);
@@ -875,8 +875,8 @@ Deno.test({ permissions: { net: true } }, async function ipv6Hostname() {
const ac = new AbortController();
let url = "";
- const consoleLog = console.log;
- console.log = (msg) => {
+ const consoleError = console.error;
+ console.error = (msg) => {
try {
const match = msg.match(/Listening on (http:\/\/(.*?):(\d+)\/)/);
assert(!!match, `Didn't match ${msg}`);
@@ -897,7 +897,7 @@ Deno.test({ permissions: { net: true } }, async function ipv6Hostname() {
assert(new URL(url), `Not a valid URL "${url}"`);
await server.shutdown();
} finally {
- console.log = consoleLog;
+ console.error = consoleError;
}
});