@nubisco/openbridge-logger 0.29.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nubisco Lda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @nubisco/openbridge-logger
2
+
3
+ Structured logger with an in-memory ring buffer and WebSocket streaming, used by the OpenBridge daemon and by plugins.
4
+
5
+ Part of [OpenBridge](https://github.com/nubisco/openbridge), a local-first home automation bridge for developers.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @nubisco/openbridge-logger
11
+ ```
12
+
13
+ Requires Node.js >= 20.
14
+
15
+ ## Documentation
16
+
17
+ See the [OpenBridge documentation](https://github.com/nubisco/openbridge#readme). This package is published from the OpenBridge monorepo and versioned in lockstep with the `openbridge` daemon.
18
+
19
+ ## License
20
+
21
+ MIT (c) Jose Silva
@@ -0,0 +1,3 @@
1
+ export type { LogLevel, LogEntry, LogListener } from './types.js';
2
+ export { Logger } from './logger.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Logger } from './logger.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { LogLevel, LogEntry, LogListener } from './types.js';
2
+ export declare class Logger {
3
+ private static listeners;
4
+ private static minLevel;
5
+ private static maxEntries;
6
+ private static entries;
7
+ static setLevel(level: LogLevel): void;
8
+ static subscribe(listener: LogListener): () => void;
9
+ static getEntries(plugin?: string, limit?: number): LogEntry[];
10
+ static clear(): void;
11
+ static create(plugin: string): {
12
+ debug: (message: string, ...args: unknown[]) => void;
13
+ info: (message: string, ...args: unknown[]) => void;
14
+ warn: (message: string, ...args: unknown[]) => void;
15
+ error: (message: string, ...args: unknown[]) => void;
16
+ };
17
+ }
18
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAIjE,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAoB;IAC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAC1C,OAAO,CAAC,MAAM,CAAC,UAAU,CAAO;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiB;IAEvC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ;IAI/B,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW;IAOtC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,QAAQ,EAAE;IAK3D,MAAM,CAAC,KAAK;IAIZ,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM;yBA8BP,MAAM,WAAW,OAAO,EAAE;wBAC3B,MAAM,WAAW,OAAO,EAAE;wBAC1B,MAAM,WAAW,OAAO,EAAE;yBACzB,MAAM,WAAW,OAAO,EAAE;;CAGhD"}
package/dist/logger.js ADDED
@@ -0,0 +1,56 @@
1
+ import { format } from 'util';
2
+ const LEVEL_ORDER = { debug: 0, info: 1, warn: 2, error: 3 };
3
+ export class Logger {
4
+ static listeners = [];
5
+ static minLevel = 'info';
6
+ static maxEntries = 1000;
7
+ static entries = [];
8
+ static setLevel(level) {
9
+ this.minLevel = level;
10
+ }
11
+ static subscribe(listener) {
12
+ this.listeners.push(listener);
13
+ return () => {
14
+ this.listeners = this.listeners.filter((l) => l !== listener);
15
+ };
16
+ }
17
+ static getEntries(plugin, limit = 200) {
18
+ const filtered = plugin ? this.entries.filter((e) => e.plugin === plugin) : this.entries;
19
+ return filtered.slice(-limit);
20
+ }
21
+ static clear() {
22
+ this.entries = [];
23
+ }
24
+ static create(plugin) {
25
+ const log = (level, message, args) => {
26
+ if (LEVEL_ORDER[level] < LEVEL_ORDER[Logger.minLevel])
27
+ return;
28
+ // Resolve printf-style placeholders (%s, %d, %o) used by Homebridge plugins
29
+ const formatted = args.length > 0 ? format(message, ...args) : message;
30
+ const entry = {
31
+ timestamp: new Date().toISOString(),
32
+ level,
33
+ plugin,
34
+ message: formatted,
35
+ };
36
+ Logger.entries.push(entry);
37
+ if (Logger.entries.length > Logger.maxEntries) {
38
+ Logger.entries.shift();
39
+ }
40
+ Logger.listeners.forEach((l) => l(entry));
41
+ // Also write to stdout with color
42
+ const color = { debug: '\x1b[90m', info: '\x1b[36m', warn: '\x1b[33m', error: '\x1b[31m' }[level];
43
+ const reset = '\x1b[0m';
44
+ const pluginTag = plugin !== 'system' ? `\x1b[35m[${plugin}]\x1b[0m ` : '';
45
+ const levelTag = `${color}[${level.toUpperCase()}]${reset}`;
46
+ console.log(`${entry.timestamp} ${levelTag} ${pluginTag}${formatted}`);
47
+ };
48
+ return {
49
+ debug: (message, ...args) => log('debug', message, args),
50
+ info: (message, ...args) => log('info', message, args),
51
+ warn: (message, ...args) => log('warn', message, args),
52
+ error: (message, ...args) => log('error', message, args),
53
+ };
54
+ }
55
+ }
56
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAG7B,MAAM,WAAW,GAA6B,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;AAEtF,MAAM,OAAO,MAAM;IACT,MAAM,CAAC,SAAS,GAAkB,EAAE,CAAA;IACpC,MAAM,CAAC,QAAQ,GAAa,MAAM,CAAA;IAClC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAA;IACxB,MAAM,CAAC,OAAO,GAAe,EAAE,CAAA;IAEvC,MAAM,CAAC,QAAQ,CAAC,KAAe;QAC7B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;IACvB,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,QAAqB;QACpC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC7B,OAAO,GAAG,EAAE;YACV,IAAI,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{
3
+ timestamp: string;
4
+ level: LogLevel;
5
+ plugin: string;
6
+ message: string;
7
+ args?: unknown[];
8
+ }
9
+ export type LogListener = (entry: LogEntry) => void;
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE1D,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,QAAQ,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;CACjB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@nubisco/openbridge-logger",
3
+ "version": "0.29.0",
4
+ "description": "Structured logger with in-memory buffer and WebSocket streaming for OpenBridge",
5
+ "author": "José Silva <jose@nubisco.io>",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/nubisco/openbridge#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/nubisco/openbridge.git",
11
+ "directory": "packages/logger"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/nubisco/openbridge/issues"
15
+ },
16
+ "keywords": [
17
+ "logger",
18
+ "structured-logging",
19
+ "typescript",
20
+ "openbridge"
21
+ ],
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/index.js",
28
+ "types": "./dist/index.d.ts"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist/",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "engines": {
37
+ "node": ">=20"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "devDependencies": {
43
+ "typescript": "^5.4.0",
44
+ "@types/node": "^20.0.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc",
48
+ "dev": "tsc --watch",
49
+ "typecheck": "tsc --noEmit"
50
+ }
51
+ }