@loglayer/transport-pretty-terminal 5.0.2 → 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 +7 -24
- 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 +6 -7
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
|
@@ -33,9 +33,6 @@ let wrap_ansi = require("wrap-ansi");
|
|
|
33
33
|
wrap_ansi = __toESM(wrap_ansi);
|
|
34
34
|
let cli_truncate = require("cli-truncate");
|
|
35
35
|
cli_truncate = __toESM(cli_truncate);
|
|
36
|
-
let node_path = require("node:path");
|
|
37
|
-
let better_sqlite3 = require("better-sqlite3");
|
|
38
|
-
better_sqlite3 = __toESM(better_sqlite3);
|
|
39
36
|
let keypress = require("keypress");
|
|
40
37
|
keypress = __toESM(keypress);
|
|
41
38
|
|
|
@@ -692,12 +689,7 @@ var LogRenderer = class {
|
|
|
692
689
|
//#endregion
|
|
693
690
|
//#region src/LogStorage.ts
|
|
694
691
|
/**
|
|
695
|
-
* LogStorage handles the persistence of log entries using SQLite.
|
|
696
|
-
* Uses an in-memory database for fast access and temporary storage.
|
|
697
|
-
*/
|
|
698
|
-
/**
|
|
699
692
|
* Handles storage and retrieval of log entries using SQLite.
|
|
700
|
-
* Uses an in-memory database for optimal performance and automatic cleanup.
|
|
701
693
|
*
|
|
702
694
|
* The database schema includes:
|
|
703
695
|
* - id: Unique identifier for each log
|
|
@@ -707,18 +699,9 @@ var LogRenderer = class {
|
|
|
707
699
|
* - data: Optional structured data as JSON string
|
|
708
700
|
*/
|
|
709
701
|
var LogStorage = class {
|
|
710
|
-
/** SQLite database instance */
|
|
711
702
|
db;
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
* Initializes a SQLite database and creates the logs table.
|
|
715
|
-
*
|
|
716
|
-
* @param logFile - Optional path to SQLite file for persistent storage.
|
|
717
|
-
* If not provided, uses in-memory database.
|
|
718
|
-
* Relative paths are resolved from the current working directory.
|
|
719
|
-
*/
|
|
720
|
-
constructor(logFile) {
|
|
721
|
-
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;
|
|
722
705
|
this.initializeDatabase();
|
|
723
706
|
}
|
|
724
707
|
/**
|
|
@@ -1577,7 +1560,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1577
1560
|
* @param config - Configuration options for the transport
|
|
1578
1561
|
* @throws Error if attempting to create multiple instances
|
|
1579
1562
|
*/
|
|
1580
|
-
constructor(config
|
|
1563
|
+
constructor(config) {
|
|
1581
1564
|
if (PrettyTerminalTransport.instance) throw new Error("PrettyTerminalTransport is a singleton. Use getPrettyTerminal() instead.");
|
|
1582
1565
|
super(config);
|
|
1583
1566
|
this.config = config;
|
|
@@ -1585,7 +1568,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1585
1568
|
const maxInlineDepth = config.maxInlineDepth || 4;
|
|
1586
1569
|
const maxInlineLength = config.maxInlineLength || 120;
|
|
1587
1570
|
const theme = config.theme || moonlight;
|
|
1588
|
-
const
|
|
1571
|
+
const database = config.database;
|
|
1589
1572
|
const simpleViewConfig = {
|
|
1590
1573
|
colors: {
|
|
1591
1574
|
trace: chalk.default.gray,
|
|
@@ -1632,7 +1615,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1632
1615
|
...theme.detailedView?.jsonColors
|
|
1633
1616
|
}
|
|
1634
1617
|
};
|
|
1635
|
-
this.storage = new LogStorage(
|
|
1618
|
+
this.storage = new LogStorage(database);
|
|
1636
1619
|
this.renderer = new LogRenderer(simpleViewConfig, detailedViewConfig, maxInlineDepth, maxInlineLength);
|
|
1637
1620
|
this.uiManager = new UIManager(this.renderer, this.storage, config.disableInteractiveMode);
|
|
1638
1621
|
PrettyTerminalTransport.instance = this;
|
|
@@ -1644,7 +1627,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1644
1627
|
* @param config - Configuration options for the transport
|
|
1645
1628
|
* @returns The singleton instance of PrettyTerminalTransport
|
|
1646
1629
|
*/
|
|
1647
|
-
static getInstance(config
|
|
1630
|
+
static getInstance(config) {
|
|
1648
1631
|
if (!PrettyTerminalTransport.instance) PrettyTerminalTransport.instance = new PrettyTerminalTransport(config);
|
|
1649
1632
|
return PrettyTerminalTransport.instance;
|
|
1650
1633
|
}
|
|
@@ -1689,7 +1672,7 @@ var PrettyTerminalTransport = class PrettyTerminalTransport extends _loglayer_tr
|
|
|
1689
1672
|
|
|
1690
1673
|
//#endregion
|
|
1691
1674
|
//#region src/index.ts
|
|
1692
|
-
function getPrettyTerminal(config
|
|
1675
|
+
function getPrettyTerminal(config) {
|
|
1693
1676
|
return PrettyTerminalTransport.getInstance(config);
|
|
1694
1677
|
}
|
|
1695
1678
|
|