summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-01-19 17:05:34 -0300
committerSebastian <sebasjm@gmail.com>2023-01-19 17:05:34 -0300
commit346056ca91d5d91fa3392217c24e8d1e32c91c54 (patch)
tree96496ed54196e86cb1baa6f1a94442679df806d8 /packages/taler-wallet-webextension
parent40279ae7f0520b25f5aecf5b2318a1bb5772c10c (diff)
downloadwallet-core-346056ca91d5d91fa3392217c24e8d1e32c91c54.tar.gz
wallet-core-346056ca91d5d91fa3392217c24e8d1e32c91c54.tar.bz2
wallet-core-346056ca91d5d91fa3392217c24e8d1e32c91c54.zip
feat: adjust log level from developer page
Diffstat (limited to 'packages/taler-wallet-webextension')
-rw-r--r--packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx1
-rw-r--r--packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx43
-rw-r--r--packages/taler-wallet-webextension/src/wxApi.ts13
-rw-r--r--packages/taler-wallet-webextension/src/wxBackend.ts13
4 files changed, 66 insertions, 4 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx
index 10e0e68d5..71227ace1 100644
--- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx
+++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx
@@ -16,7 +16,6 @@
import { format } from "date-fns";
import { h, VNode } from "preact";
-import { ErrorTalerOperation } from "../../components/ErrorTalerOperation.js";
import { LogoHeader } from "../../components/LogoHeader.js";
import { Part } from "../../components/Part.js";
import {
diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx
index 3df3a470c..ee0986076 100644
--- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx
@@ -19,6 +19,7 @@ import {
CoinDumpJson,
CoinStatus,
ExchangeListItem,
+ LogLevel,
NotificationType,
} from "@gnu-taler/taler-util";
import {
@@ -29,6 +30,7 @@ import { format } from "date-fns";
import { Fragment, h, VNode } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
import { Diagnostics } from "../components/Diagnostics.js";
+import { SelectList } from "../components/SelectList.js";
import { NotifyUpdateFadeOut } from "../components/styled/index.js";
import { Time } from "../components/Time.js";
import { useBackendContext } from "../context/backend.js";
@@ -37,6 +39,8 @@ import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { useDiagnostics } from "../hooks/useDiagnostics.js";
import { Button } from "../mui/Button.js";
import { Grid } from "../mui/Grid.js";
+import { Paper } from "../mui/Paper.js";
+import { TextField } from "../mui/TextField.js";
export function DeveloperPage(): VNode {
const [status, timedOut] = useDiagnostics();
@@ -167,6 +171,9 @@ export function View({
[exchange_name: string]: CalculatedCoinfInfo[];
},
);
+
+ const [tagName, setTagName] = useState("");
+ const [logLevel, setLogLevel] = useState("info");
return (
<div>
<p>
@@ -312,6 +319,42 @@ export function View({
</Button>
</Grid>{" "}
</Grid>
+ <Paper style={{ padding: 10, margin: 10 }}>
+ <h3>Logging</h3>
+ <div>
+ <TextField
+ label="Tag name"
+ placeholder="wallet.ts"
+ variant="filled"
+ // error={subject.error}
+ required
+ value={tagName}
+ onChange={setTagName}
+ />
+ <SelectList
+ label={i18n.str`Log levels`}
+ list={{
+ trace: "TRACE",
+ info: "INFO",
+ error: "ERROR",
+ }}
+ name="logLevel"
+ value={logLevel}
+ onChange={(v) => setLogLevel(v)}
+ />
+ </div>
+ <Button
+ variant="contained"
+ onClick={async () => {
+ api.background.call("setLoggingLevel", {
+ tag: tagName,
+ level: logLevel as LogLevel,
+ });
+ }}
+ >
+ Set log level
+ </Button>
+ </Paper>
{downloadedDatabase && (
<div>
<i18n.Translate>
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts
index 58ca48745..001f77934 100644
--- a/packages/taler-wallet-webextension/src/wxApi.ts
+++ b/packages/taler-wallet-webextension/src/wxApi.ts
@@ -25,6 +25,7 @@ import {
AbsoluteTime,
CoreApiResponse,
Logger,
+ LogLevel,
NotificationType,
TalerErrorCode,
TalerErrorDetail,
@@ -85,6 +86,13 @@ export interface BackgroundOperations {
request: void;
response: void;
};
+ setLoggingLevel: {
+ request: {
+ tag?: string,
+ level: LogLevel
+ };
+ response: void;
+ };
}
export interface BackgroundApiClient {
@@ -122,7 +130,6 @@ class BackgroundApiClientImpl implements BackgroundApiClient {
try {
response = await platform.sendMessageToBackground(message);
} catch (error) {
- console.log("Error calling backend");
if (error instanceof Error) {
throw new BackgroundError(operation, {
code: TalerErrorCode.GENERIC_UNEXPECTED_REQUEST_ERROR,
@@ -131,13 +138,13 @@ class BackgroundApiClientImpl implements BackgroundApiClient {
}
throw error;
}
- logger.info("got response", response);
if (response.type === "error") {
throw new BackgroundError(
`Background operation "${operation}" failed`,
response.error,
);
}
+ logger.trace("response", response);
return response.result as any;
}
}
@@ -162,13 +169,13 @@ class WalletApiClientImpl implements WalletCoreApiClient {
console.log("Error calling backend");
throw new Error(`Error contacting backend: ${e}`);
}
- logger.info("got response", response);
if (response.type === "error") {
throw new BackgroundError(
`Wallet operation "${operation}" failed`,
response.error,
);
}
+ logger.trace("got response", response);
return response.result as any;
}
}
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts
index c7b964c28..1bfee1064 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -26,6 +26,9 @@
import {
classifyTalerUri,
Logger,
+ LogLevel,
+ setGlobalLogLevelFromString,
+ setLogLevelFromString,
TalerErrorCode,
TalerUriType,
WalletDiagnostics,
@@ -180,8 +183,18 @@ const backendHandlers: BackendHandlerType = {
resetDb,
runGarbageCollector,
toggleHeaderListener,
+ setLoggingLevel,
};
+async function setLoggingLevel({ tag, level }: { tag?: string, level: LogLevel }): Promise<void> {
+ logger.info(`setting ${tag} to ${level}`)
+ if (!tag) {
+ setGlobalLogLevelFromString(level)
+ } else {
+ setLogLevelFromString(tag, level)
+ }
+}
+
async function dispatch<Op extends WalletOperations | BackgroundOperations>(
req: MessageFromFrontend<Op> & { id: string },
): Promise<MessageResponse> {