@loglayer/transport-pretty-terminal 5.0.1 → 6.0.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 +1 -1
- package/README.md +66 -1
- package/dist/index.cjs +9 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -6
- package/dist/index.d.mts +38 -6
- package/dist/index.mjs +7 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -11
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 Theo Gravity / [Disaresta](https://disaresta.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@loglayer/transport-pretty-terminal)
|
|
4
4
|
[](https://www.npmjs.com/package/@loglayer/transport-pretty-terminal)
|
|
5
5
|
[](http://www.typescriptlang.org/)
|
|
6
|
+
[](https://bun.sh)
|
|
6
7
|
|
|
7
8
|
A transport for the [LogLayer](https://loglayer.dev) logging library that pretty-prints logs printed in the terminal.
|
|
8
9
|
|
|
@@ -27,4 +28,68 @@ Use [Simple Pretty terminal](https://loglayer.dev/transports/simple-pretty-termi
|
|
|
27
28
|
|
|
28
29
|
## Installation
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
### Node.js
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install loglayer @loglayer/transport-pretty-terminal serialize-error better-sqlite3
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Bun
|
|
38
|
+
|
|
39
|
+
Bun has a built-in SQLite module — `better-sqlite3` is not needed. Pass a `bun:sqlite` `Database` via the `database` option (see usage below).
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
bun add loglayer @loglayer/transport-pretty-terminal serialize-error
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### Node.js
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import Database from 'better-sqlite3';
|
|
51
|
+
import { LogLayer, ConsoleTransport } from 'loglayer';
|
|
52
|
+
import { getPrettyTerminal } from '@loglayer/transport-pretty-terminal';
|
|
53
|
+
import { serializeError } from 'serialize-error';
|
|
54
|
+
|
|
55
|
+
const log = new LogLayer({
|
|
56
|
+
errorSerializer: serializeError,
|
|
57
|
+
transport: [
|
|
58
|
+
new ConsoleTransport({
|
|
59
|
+
// Use console logging in non-development environments
|
|
60
|
+
enabled: process.env.NODE_ENV !== 'development',
|
|
61
|
+
}),
|
|
62
|
+
getPrettyTerminal({
|
|
63
|
+
database: new Database(':memory:'),
|
|
64
|
+
// Only enable Pretty Terminal in development
|
|
65
|
+
enabled: process.env.NODE_ENV === 'development',
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Bun
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { Database } from 'bun:sqlite';
|
|
75
|
+
import { LogLayer, ConsoleTransport } from 'loglayer';
|
|
76
|
+
import { getPrettyTerminal } from '@loglayer/transport-pretty-terminal';
|
|
77
|
+
import { serializeError } from 'serialize-error';
|
|
78
|
+
|
|
79
|
+
const log = new LogLayer({
|
|
80
|
+
errorSerializer: serializeError,
|
|
81
|
+
transport: [
|
|
82
|
+
new ConsoleTransport({
|
|
83
|
+
// Use console logging in non-development environments
|
|
84
|
+
enabled: process.env.NODE_ENV !== 'development',
|
|
85
|
+
}),
|
|
86
|
+
getPrettyTerminal({
|
|
87
|
+
database: new Database(':memory:'),
|
|
88
|
+
// Only enable Pretty Terminal in development
|
|
89
|
+
enabled: process.env.NODE_ENV === 'development',
|
|
90
|
+
}),
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
For full documentation visit the [Pretty Terminal docs](https://loglayer.dev/transports/pretty-terminal).
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -32,9 +33,6 @@ let wrap_ansi = require("wrap-ansi");
|
|
|
32
33
|
wrap_ansi = __toESM(wrap_ansi);
|
|
33
34
|
let cli_truncate = require("cli-truncate");
|
|
34
35
|
cli_truncate = __toESM(cli_truncate);
|
|
35
|
-
let node_path = require("node:path");
|
|
36
|
-
let better_sqlite3 = require("better-sqlite3");
|
|
37
|
-
better_sqlite3 = __toESM(better_sqlite3);
|
|
38
36
|
let keypress = require("keypress");
|
|
39
37
|
keypress = __toESM(keypress);
|
|
40
38
|
|
|
@@ -691,12 +689,7 @@ var LogRenderer = class {
|
|
|
691
689
|
//#endregion
|
|
692
690
|
//#region src/LogStorage.ts
|
|
693
691
|
/**
|
|
694
|
-
* LogStorage handles the persistence of log entries using SQLite.
|
|
695
|
-
* Uses an in-memory database for fast access and temporary storage.
|
|
696
|
-
*/
|
|
697
|
-
/**
|
|
698
692
|
* Handles storage and retrieval of log entries using SQLite.
|
|
699
|
-
* Uses an in-memory database for optimal performance and automatic cleanup.
|
|
700
693
|
*
|
|
701
694
|
* The database schema includes:
|
|
702
695
|
* - id: Unique identifier for each log
|
|
@@ -706,18 +699,9 @@ var LogRenderer = class {
|
|
|
706
699
|
* - data: Optional structured data as JSON string
|
|
707
700
|
*/
|
|
708
701
|
var LogStorage = class {
|
|
709
|
-
/** SQLite database instance */
|
|
710
702
|
db;
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
* Initializes a SQLite database and creates the logs table.
|
|
714
|
-
*
|
|
715
|
-
* @param logFile - Optional path to SQLite file for persistent storage.
|
|
716
|
-
* If not provided, uses in-memory database.
|
|
717
|
-
* Relative paths are resolved from the current working directory.
|
|
718
|
-
*/
|
|
719
|
-
constructor(logFile) {
|
|
720
|
-
this.db = new better_sqlite3.default(logFile ? logFile.startsWith("/") ? logFile : (0, node_path.resolve)(process.cwd(), logFile) : ":memory:");
|
|
703
|
+
constructor(database) {
|
|
704
|
+
this.db = database;
|
|
721
705
|
this.initializeDatabase();
|
|
722
706
|
}
|
|
723
707
|
/**
|
|
@@ -1576,7 +1560,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1576
1560
|
* @param config - Configuration options for the transport
|
|
1577
1561
|
* @throws Error if attempting to create multiple instances
|
|
1578
1562
|
*/
|
|
1579
|
-
constructor(config
|
|
1563
|
+
constructor(config) {
|
|
1580
1564
|
if (PrettyTerminalTransport.instance) throw new Error("PrettyTerminalTransport is a singleton. Use getPrettyTerminal() instead.");
|
|
1581
1565
|
super(config);
|
|
1582
1566
|
this.config = config;
|
|
@@ -1584,7 +1568,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1584
1568
|
const maxInlineDepth = config.maxInlineDepth || 4;
|
|
1585
1569
|
const maxInlineLength = config.maxInlineLength || 120;
|
|
1586
1570
|
const theme = config.theme || moonlight;
|
|
1587
|
-
const
|
|
1571
|
+
const database = config.database;
|
|
1588
1572
|
const simpleViewConfig = {
|
|
1589
1573
|
colors: {
|
|
1590
1574
|
trace: chalk.default.gray,
|
|
@@ -1631,7 +1615,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1631
1615
|
...theme.detailedView?.jsonColors
|
|
1632
1616
|
}
|
|
1633
1617
|
};
|
|
1634
|
-
this.storage = new LogStorage(
|
|
1618
|
+
this.storage = new LogStorage(database);
|
|
1635
1619
|
this.renderer = new LogRenderer(simpleViewConfig, detailedViewConfig, maxInlineDepth, maxInlineLength);
|
|
1636
1620
|
this.uiManager = new UIManager(this.renderer, this.storage, config.disableInteractiveMode);
|
|
1637
1621
|
PrettyTerminalTransport.instance = this;
|
|
@@ -1643,7 +1627,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1643
1627
|
* @param config - Configuration options for the transport
|
|
1644
1628
|
* @returns The singleton instance of PrettyTerminalTransport
|
|
1645
1629
|
*/
|
|
1646
|
-
static getInstance(config
|
|
1630
|
+
static getInstance(config) {
|
|
1647
1631
|
if (!PrettyTerminalTransport.instance) PrettyTerminalTransport.instance = new PrettyTerminalTransport(config);
|
|
1648
1632
|
return PrettyTerminalTransport.instance;
|
|
1649
1633
|
}
|
|
@@ -1688,7 +1672,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1688
1672
|
|
|
1689
1673
|
//#endregion
|
|
1690
1674
|
//#region src/index.ts
|
|
1691
|
-
function getPrettyTerminal(config
|
|
1675
|
+
function getPrettyTerminal(config) {
|
|
1692
1676
|
return PrettyTerminalTransport.getInstance(config);
|
|
1693
1677
|
}
|
|
1694
1678
|
|