@bsv/wallet-toolbox 1.7.4 → 1.7.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/wallet-toolbox",
3
- "version": "1.7.4",
3
+ "version": "1.7.6",
4
4
  "description": "BRC100 conforming wallet, wallet storage and wallet signer components",
5
5
  "main": "./out/src/index.js",
6
6
  "types": "./out/src/index.d.ts",
@@ -7,6 +7,7 @@ export class WalletLogger implements WalletLoggerInterface {
7
7
  isOrigin: boolean = true
8
8
  isError: boolean = false
9
9
  level?: WalletLoggerLevel
10
+ flushFormat?: 'json'
10
11
 
11
12
  constructor(log?: string | WalletLoggerInterface) {
12
13
  if (log) {
@@ -107,9 +108,20 @@ export class WalletLogger implements WalletLoggerInterface {
107
108
  }
108
109
 
109
110
  flush(): object | undefined {
110
- const log = this.toLogString()
111
- if (this.isError) console.error(log)
112
- else console.log(log)
111
+ if (this.logs.length > 0) {
112
+ const trace = this.toLogString()
113
+ const output = this.isError ? console.error : console.log
114
+ if (this.flushFormat === 'json') {
115
+ const name = this.logs[0].log
116
+ const log = {
117
+ name,
118
+ trace
119
+ }
120
+ output(JSON.stringify(log))
121
+ } else {
122
+ output(trace)
123
+ }
124
+ }
113
125
  const r = this.isOrigin ? undefined : this.toWalletLoggerJson()
114
126
  return r
115
127
  }
@@ -165,3 +177,37 @@ export function logCreateActionArgs(args: CreateActionArgs): object {
165
177
  * 'trace' Instead of adding debug details, focus on execution path and timing.
166
178
  */
167
179
  export type WalletLoggerLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace'
180
+
181
+ /**
182
+ * Constructor properties available to `WalletLogger`
183
+ */
184
+ export interface WalletLoggerArgs {
185
+ /**
186
+ * Optional. Logging levels that may influence what is logged.
187
+ *
188
+ * 'error' Only requests resulting in an exception should be logged.
189
+ * 'warn' Also log requests that succeed but with an abnormal condition.
190
+ * 'info' Also log normal successful requests.
191
+ * 'debug' Add input parm and result details where possible.
192
+ * 'trace' Instead of adding debug details, focus on execution path and timing.
193
+ */
194
+ level?: 'error' | 'warn' | 'info' | 'debug' | 'trace'
195
+
196
+ /**
197
+ * Valid if an accumulating logger. Count of `group` calls without matching `groupEnd`.
198
+ */
199
+ indent?: number
200
+ /**
201
+ * True if this is an accumulating logger and the logger belongs to the object servicing the initial request.
202
+ */
203
+ isOrigin?: boolean
204
+ /**
205
+ * True if this is an accumulating logger and an error was logged.
206
+ */
207
+ isError?: boolean
208
+
209
+ /**
210
+ * Optional array of accumulated logged data and errors.
211
+ */
212
+ logs?: WalletLoggerLog[]
213
+ }