Skip to content

Commit 9d1f851

Browse files
committed
fix(logging): improve remote logging and debug mode support
- Add debug log level support and corresponding console.debug override - Introduce enableDebug method to activate debug logging via UI button - Fix console method argument spreading to handle empty arguments properly - Add new bug icon button in settings page to toggle debug logging mode - Implement toast notification on enabling debug mode - Update logging write function to respect debug activation flag - Change default cache state in @analogjs/trpc from active to inactive - Change console.log to console.info for device linking success messages - Add CSS classes for responsive element visibility (.hidden, .mobile-hidden) - Replace hidden class usage to hide text on mobile for web navigation items - Add cache-control header to disable caching in trpc server responses - Remove stray trailing whitespace and unnecessary blank lines in code files
1 parent 498d94c commit 9d1f851

File tree

23 files changed

+113
-34
lines changed

23 files changed

+113
-34
lines changed

mobile/patches/@analogjs+trpc+0.4.0.patch

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
diff --git a/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs b/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs
2-
index fd3f2b7..564f690 100644
2+
index fd3f2b7..ac5dcd8 100644
33
--- a/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs
44
+++ b/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs
5+
@@ -9,7 +9,7 @@ import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
6+
const tRPC_CACHE_STATE = new InjectionToken('TRPC_HTTP_TRANSFER_STATE_CACHE_STATE');
7+
const provideTrpcCacheState = () => ({
8+
provide: tRPC_CACHE_STATE,
9+
- useValue: { isCacheActive: new BehaviorSubject(true) },
10+
+ useValue: { isCacheActive: new BehaviorSubject(false) },
11+
});
12+
const provideTrpcCacheStateStatusManager = () => ({
13+
provide: APP_BOOTSTRAP_LISTENER,
514
@@ -269,7 +269,7 @@ const createTrpcClient = ({ url, options, batchLinkOptions, }) => {
615
headers() {
716
return TrpcHeaders();

mobile/src/app/dashboard/dashboard.page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export class DashboardPage {
219219
// Fetch dashboard info using deviceId
220220
// Using a simple approach to avoid type issues
221221
const response = await this.deviceService.info();
222+
222223
this.dashboardInfo$.next(response);
223224
} catch (err) {
224225
this.dashboardInfo$.next(null);

mobile/src/app/qr-code/qr-code.page.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export class QrCodePage {
302302
);
303303
}),
304304
tap((data) => {
305-
console.log('Device linked successfully:', data);
305+
console.info('Device linked successfully:', data);
306306
if (data && typeof data === 'object' && 'id' in data) {
307307
this.scanResultQrData$.next(data);
308308
// Navigate to the dashboard tab after successful linking
@@ -395,7 +395,7 @@ export class QrCodePage {
395395
.pipe(
396396
first(),
397397
tap((data: any) => {
398-
console.log('Device linked successfully:', data);
398+
console.info('Device linked successfully:', data);
399399
if (data && typeof data === 'object' && 'id' in data) {
400400
this.scanResultQrData$.next(data);
401401
// Navigate to the dashboard tab after successful linking

mobile/src/app/remote-log.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@ let _log: Function;
44
let _warn: Function;
55
let _error: Function;
66
let _info: Function;
7+
let _debug: Function;
78
let _pending: Array<LogItem> | undefined = undefined;
89
let _callback: (data: any) => void;
910
interface LogItem {
1011
message: string;
1112
level: string;
1213
}
1314

15+
export function activateSendLoggerMessageToServer() {
16+
(window as any).debug = true;
17+
}
1418
/**
1519
* Initialize logging will override window.console and send to the serverUrl
1620
* @param {string} serverUrl The servername and port number of the remote server (eg 192.168.1.1:9000)
1721
*/
1822
export function initLogger(callback: (data: any) => void) {
1923
_log = window.console.log;
20-
_warn = window.console.error;
24+
_warn = window.console.warn;
2125
_error = window.console.error;
2226
_info = window.console.info;
27+
_debug = window.console.debug;
2328
_callback = callback;
2429
window.console.log = consoleLog;
2530
window.console.warn = consoleWarn;
2631
window.console.error = consoleError;
32+
window.console.debug = consoleDebug;
2733
(window.console as any).hiddenError = hiddenError;
2834
window.console.info = consoleInfo;
2935

@@ -43,6 +49,9 @@ export function initLogger(callback: (data: any) => void) {
4349
}
4450

4551
function write(message: any, _arguments: any, level: string) {
52+
if (!(window as any).debug) {
53+
return;
54+
}
4655
const args = Array.prototype.slice.call(_arguments);
4756
let msg = message;
4857
args.forEach((element) => {
@@ -92,17 +101,17 @@ function post(data: any) {
92101
}
93102

94103
function consoleLog(message: any, ...args: any) {
95-
_log(message, ...args);
104+
_log(message, ...(args || []));
96105
write(message, args, 'log');
97106
}
98107

99108
function consoleWarn(message: any, ...args: any) {
100-
_warn(message, ...args);
109+
_warn(message, ...(args || []));
101110
write(message, args, 'warn');
102111
}
103112

104113
function consoleError(message: any, ...args: any) {
105-
_error(message, ...args);
114+
_error(message, ...(args || []));
106115
write(message, args, 'error');
107116
}
108117

@@ -111,6 +120,11 @@ function hiddenError(message: any, ...args: any) {
111120
}
112121

113122
function consoleInfo(message: any, ...args: any) {
114-
_info(message, ...args);
123+
_info(message, ...(args || []));
115124
write(message, args, 'info');
116125
}
126+
127+
function consoleDebug(message: any, ...args: any) {
128+
_debug(message, ...(args || []));
129+
write(message, args, 'debug');
130+
}

mobile/src/app/services/device.service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ export class DeviceService {
1414

1515
info() {
1616
return firstValueFrom(
17-
this.trpc.device.info
18-
.query()
19-
.pipe(tap((info) => this.setDarkTheme(!!info.isBlackTheme)))
17+
this.trpc.device.info.query().pipe(
18+
tap((info) => {
19+
this.setDarkTheme(!!info.isBlackTheme);
20+
})
21+
)
2022
);
2123
}
2224

mobile/src/app/settings/settings.page.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
refreshOutline,
3030
saveOutline,
3131
unlinkOutline,
32+
bugOutline,
3233
} from 'ionicons/icons';
3334
import { BehaviorSubject } from 'rxjs';
3435
import { X_DEVICE_ID } from '../../../../web/src/server/constants';
@@ -37,6 +38,7 @@ import { DeviceService } from '../services/device.service';
3738
import { ErrorHandlerService } from '../services/error-handler.service';
3839
import { TrpcHeaders } from '../trpc-client';
3940
import { TrpcPureHeaders } from '../trpc-pure-client';
41+
import { activateSendLoggerMessageToServer } from '../remote-log';
4042

4143
@Component({
4244
selector: 'app-settings',
@@ -49,6 +51,9 @@ import { TrpcPureHeaders } from '../trpc-pure-client';
4951
<ion-toolbar>
5052
<ion-title> Settings </ion-title>
5153
<ion-buttons slot="end">
54+
<ion-button (click)="enableDebug()">
55+
<ion-icon name="bug-outline"></ion-icon>
56+
</ion-button>
5257
<ion-button (click)="loadDashboardInfo()" [disabled]="loading">
5358
<ion-icon name="refresh-outline"></ion-icon>
5459
</ion-button>
@@ -194,7 +199,13 @@ export class SettingsPage {
194199
loading$ = new BehaviorSubject(false);
195200

196201
constructor() {
197-
addIcons({ refreshOutline, saveOutline, qrCodeOutline, unlinkOutline });
202+
addIcons({
203+
refreshOutline,
204+
saveOutline,
205+
qrCodeOutline,
206+
unlinkOutline,
207+
bugOutline,
208+
});
198209
// Initialize the error handler with the toast controller
199210
this.errorHandler.initialize(this.toastController);
200211
}
@@ -203,6 +214,17 @@ export class SettingsPage {
203214
await this.loadDashboardInfo();
204215
}
205216

217+
enableDebug() {
218+
activateSendLoggerMessageToServer();
219+
this.toastController
220+
.create({
221+
message: 'Debug mode enabled',
222+
duration: 2000,
223+
color: 'success',
224+
})
225+
.then((toast) => toast.present());
226+
}
227+
206228
async loadDashboardInfo() {
207229
// Set loading state to true when starting to load data
208230
this.loading$.next(true);

mobile/src/app/trpc-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function customFetch(
6363
});
6464
}
6565

66-
export const { provideTrpcClient, TrpcClient, TrpcHeaders } =
66+
export const { provideTrpcClient, TrpcClient, TrpcHeaders} =
6767
createTrpcClient<AppRouter>({
6868
url: `${environment.apiUrl}/api/trpc`,
6969
options: { transformer: superjson },

mobile/src/global.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,16 @@ a {
402402
background-color: #1e3a8a;
403403
}
404404

405+
.hidden {
406+
display: none;
407+
}
408+
409+
.mobile-hidden {
410+
@media (max-width: 1023px) {
411+
display: none;
412+
}
413+
}
414+
405415
ion-title {
406416
padding: 20px;
407417
}

web/patches/@analogjs+trpc+0.4.0.patch

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
diff --git a/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs b/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs
2-
index fd3f2b7..564f690 100644
2+
index fd3f2b7..ac5dcd8 100644
33
--- a/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs
44
+++ b/node_modules/@analogjs/trpc/fesm2022/analogjs-trpc.mjs
5+
@@ -9,7 +9,7 @@ import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
6+
const tRPC_CACHE_STATE = new InjectionToken('TRPC_HTTP_TRANSFER_STATE_CACHE_STATE');
7+
const provideTrpcCacheState = () => ({
8+
provide: tRPC_CACHE_STATE,
9+
- useValue: { isCacheActive: new BehaviorSubject(true) },
10+
+ useValue: { isCacheActive: new BehaviorSubject(false) },
11+
});
12+
const provideTrpcCacheStateStatusManager = () => ({
13+
provide: APP_BOOTSTRAP_LISTENER,
514
@@ -269,7 +269,7 @@ const createTrpcClient = ({ url, options, batchLinkOptions, }) => {
615
headers() {
716
return TrpcHeaders();

web/src/app/app.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const routeMeta: RouteMeta = {
6464
name="layout-dashboard"
6565
class="w-8 h-8 lg:mr-2 inline-block align-middle"
6666
></i-lucide>
67-
<span class="hidden lg:inline align-middle">My Dashboards</span>
67+
<span class="mobile-hidden lg:inline align-middle">My Dashboards</span>
6868
</a>
6969
7070
<nav class="flex flex-col space-y-4 w-full">
@@ -73,7 +73,7 @@ export const routeMeta: RouteMeta = {
7373
class="flex items-center p-3 rounded-xl bg-pastel-blue/10 text-pastel-blue font-semibold transition-all duration-300 hover:bg-pastel-blue/20"
7474
>
7575
<i-lucide name="grid-3x3" class="w-6 h-6 mr-0 lg:mr-3"></i-lucide>
76-
<span class="hidden lg:inline">Dashboards</span>
76+
<span class="mobile-hidden lg:inline">Dashboards</span>
7777
</a>
7878
7979
<a
@@ -84,15 +84,15 @@ export const routeMeta: RouteMeta = {
8484
name="chart-bar-big"
8585
class="w-6 h-6 mr-0 lg:mr-3"
8686
></i-lucide>
87-
<span class="hidden lg:inline">Analytics</span>
87+
<span class="mobile-hidden lg:inline">Analytics</span>
8888
</a>
8989
9090
<a
9191
href="/settings"
9292
class="flex items-center p-3 rounded-xl text-gray-600 font-medium transition-all duration-300 hover:bg-gray-100 hover:text-gray-800"
9393
>
9494
<i-lucide name="settings" class="w-6 h-6 mr-0 lg:mr-3"></i-lucide>
95-
<span class="hidden lg:inline">Settings</span>
95+
<span class="mobile-hidden lg:inline">Settings</span>
9696
</a>
9797
</nav>
9898
@@ -105,7 +105,7 @@ export const routeMeta: RouteMeta = {
105105
class="mt-2 text-red-500 font-medium hover:text-red-700 transition-colors flex items-center"
106106
>
107107
<i-lucide name="log-out" class="w-5 h-5 mr-0 lg:mr-2"></i-lucide>
108-
<span class="hidden lg:inline">Sign Out</span>
108+
<span class="mobile-hidden lg:inline">Sign Out</span>
109109
</button>
110110
<color-scheme-switcher class="flex items-center" />
111111
</div>

0 commit comments

Comments
 (0)