Debian Codegraph @

addons/point_of_sale/static/src/app/utils/pretty_console_log.js

raw
1 import { Logger } from "@bus/workers/bus_worker_utils";
2 import { downloadFile } from "@web/core/network/download";
3
4 const posLogger = new Logger(`point_of_sale_config_${odoo.pos_config_id}_logger`);
5
6 export function logPosMessage(type, functionName, message, color = "#A1A1A1", args = []) {
7 if (odoo.debug === "assets") {
8 console.groupCollapsed(
9 `[%c${type}%c]: %c${functionName}%c - ${message}`,
10 `color:${color};`,
11 "",
12 `font-weight:bold;`,
13 ""
14 );
15 if (args.length) {
16 console.debug(...args);
17 }
18 console.trace("Call stack:");
19 console.groupEnd();
20 }
21 const timestamp = luxon.DateTime.now().toUTC().toFormat("yyyy-LL-dd HH:mm:ss");
22 const log = {
23 timestamp,
24 type,
25 functionName,
26 message,
27 };
28 if (args.length) {
29 try {
30 log.args = JSON.parse(JSON.stringify(args));
31 } catch {
32 // In case the args are not serializable
33 log.args = args.toString();
34 }
35 }
36 posLogger.log(log);
37 }
38
39 export async function downloadPosLogs() {
40 const logs = await posLogger.getLogs();
41 const blob = new Blob([JSON.stringify(logs, null, 2)], {
42 type: "application/json",
43 });
44 const filename = `pos_logs_${luxon.DateTime.now()
45 .toUTC()
46 .toFormat("yyyy-LL-dd-HH-mm-ss")}.json`;
47 downloadFile(blob, filename);
48 }