sockethub 5.0.0-alpha.10 → 5.0.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/sockethub-logged +93 -0
  2. package/package.json +13 -10
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * Sockethub launcher with split logging:
4
+ * - Console: filtered via DEBUG pattern
5
+ * - File: full debug output to sockethub.log
6
+ */
7
+ import { spawn } from "node:child_process";
8
+ import { createWriteStream } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+ import debug from "debug";
11
+
12
+ // Console filter using DEBUG syntax
13
+ const CONSOLE_DEBUG = [
14
+ "sockethub:init",
15
+ "sockethub:server:bootstrap:*",
16
+ "sockethub:server:core",
17
+ "-sockethub:server:core:*", // exclude per-session logs
18
+ "sockethub:server:listener",
19
+ "sockethub:server:janitor",
20
+ "sockethub:server:rate-limiter",
21
+ ].join(",");
22
+
23
+ // Create a filter function using debug's enable/disable logic
24
+ debug.enable(CONSOLE_DEBUG);
25
+ const shouldShow = (namespace: string) => debug.enabled(namespace);
26
+
27
+ // Extract namespace from debug output line
28
+ // Format: " sockethub:namespace message +0ms" (with optional ANSI colors)
29
+ const namespaceRegex = /sockethub:[^\s\x1b]+/;
30
+ function getNamespace(line: string): string | null {
31
+ const match = line.match(namespaceRegex);
32
+ return match ? match[0] : null;
33
+ }
34
+
35
+ const logFile = createWriteStream("sockethub.log", { flags: "a" });
36
+ const timestamp = () => new Date().toISOString();
37
+
38
+ logFile.write(`\n--- Sockethub started at ${timestamp()} ---\n`);
39
+
40
+ const child = spawn("bun", ["run", join(dirname(import.meta.path), "sockethub")], {
41
+ env: { ...process.env, DEBUG: "sockethub:*", DEBUG_COLORS: "true" },
42
+ stdio: ["inherit", "pipe", "pipe"],
43
+ });
44
+
45
+ function processLine(line: string, stream: "stdout" | "stderr") {
46
+ // Always write to file
47
+ logFile.write(`${line}\n`);
48
+
49
+ // Check if namespace passes DEBUG filter
50
+ // Non-debug lines (console.log from init, errors) are always shown
51
+ const namespace = getNamespace(line);
52
+ const show = namespace
53
+ ? shouldShow(namespace)
54
+ : true; // show non-debug lines (startup banner, errors, etc)
55
+
56
+ if (show) {
57
+ if (stream === "stderr") {
58
+ process.stderr.write(`${line}\n`);
59
+ } else {
60
+ process.stdout.write(`${line}\n`);
61
+ }
62
+ }
63
+ }
64
+
65
+ let stdoutBuffer = "";
66
+ let stderrBuffer = "";
67
+
68
+ child.stdout?.on("data", (data) => {
69
+ stdoutBuffer += data.toString();
70
+ const lines = stdoutBuffer.split("\n");
71
+ stdoutBuffer = lines.pop() || "";
72
+ for (const line of lines) {
73
+ processLine(line, "stdout");
74
+ }
75
+ });
76
+
77
+ child.stderr?.on("data", (data) => {
78
+ stderrBuffer += data.toString();
79
+ const lines = stderrBuffer.split("\n");
80
+ stderrBuffer = lines.pop() || "";
81
+ for (const line of lines) {
82
+ processLine(line, "stderr");
83
+ }
84
+ });
85
+
86
+ child.on("close", (code) => {
87
+ logFile.write(`--- Sockethub exited with code ${code} at ${timestamp()} ---\n`);
88
+ logFile.close();
89
+ process.exit(code || 0);
90
+ });
91
+
92
+ process.on("SIGINT", () => child.kill("SIGINT"));
93
+ process.on("SIGTERM", () => child.kill("SIGTERM"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sockethub",
3
3
  "description": "A polyglot messaging service",
4
- "version": "5.0.0-alpha.10",
4
+ "version": "5.0.0-alpha.12",
5
5
  "private": false,
6
6
  "author": "Nick Jennings <nick@silverbucket.net>",
7
7
  "license": "LGPL-3.0+",
@@ -37,17 +37,20 @@
37
37
  },
38
38
  "homepage": "https://sockethub.org",
39
39
  "dependencies": {
40
- "@sockethub/platform-dummy": "^3.0.0-alpha.10",
41
- "@sockethub/platform-feeds": "^4.0.0-alpha.10",
42
- "@sockethub/platform-irc": "^4.0.0-alpha.10",
43
- "@sockethub/platform-xmpp": "^5.0.0-alpha.10",
44
- "@sockethub/server": "^5.0.0-alpha.10"
40
+ "@sockethub/platform-dummy": "^3.0.0-alpha.12",
41
+ "@sockethub/platform-feeds": "^4.0.0-alpha.12",
42
+ "@sockethub/platform-irc": "^4.0.0-alpha.12",
43
+ "@sockethub/platform-xmpp": "^5.0.0-alpha.12",
44
+ "@sockethub/server": "^5.0.0-alpha.12"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "bun build.js",
48
- "dev": "DEBUG=sockethub* bun run --hot ./bin/sockethub --examples",
49
- "info": "DEBUG=sockethub* bun run ./bin/sockethub --info",
50
- "start": "DEBUG=sockethub* bun run ./bin/sockethub"
48
+ "clean:deps": "rm -rf node_modules",
49
+ "dev": "bun run --hot ./bin/sockethub --examples",
50
+ "info": "bun run ./bin/sockethub --info",
51
+ "start": "bun run ./bin/sockethub-logged",
52
+ "start:verbose": "bun run ./bin/sockethub",
53
+ "start:quiet": "bun run ./bin/sockethub"
51
54
  },
52
- "gitHead": "8e1abf116b2a6b57d33c6e1a4af9143870517bae"
55
+ "gitHead": "f039dab3c3f67cbbf204476fc397532e973f82a8"
53
56
  }