From a2b311f9cf493b6bd2dd14999b18206dbd561273 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Thu, 16 Nov 2023 04:15:16 +0000 Subject: [PATCH] remove getConsoleStyle from logging getConsoleStyle was created when browsers did display things like json well. This is no longer the case and its color styles makes it very hard to read in dark mode. Given this removing this custom formating logging logic. --- src/onesignal/OneSignal.ts | 14 +++----------- src/page/bell/Message.ts | 7 ++----- src/shared/context/Utils.ts | 18 ------------------ src/shared/helpers/HttpHelper.ts | 6 +----- src/shared/helpers/InitHelper.ts | 10 +++------- src/shared/helpers/MainHelper.ts | 7 +------ src/shared/services/OneSignalEvent.ts | 8 ++------ src/shared/utils/OneSignalUtils.ts | 4 +--- src/shared/utils/utils.ts | 4 ---- src/sw/serviceWorker/ServiceWorker.ts | 22 ++++++---------------- src/sw/webhooks/OSWebhookSender.ts | 2 +- 11 files changed, 20 insertions(+), 82 deletions(-) diff --git a/src/onesignal/OneSignal.ts b/src/onesignal/OneSignal.ts index 00ce1af29..4359d0898 100644 --- a/src/onesignal/OneSignal.ts +++ b/src/onesignal/OneSignal.ts @@ -28,7 +28,7 @@ import { AppUserConfigNotifyButton } from '../shared/models/Prompts'; import { WindowEnvironmentKind } from '../shared/models/WindowEnvironmentKind'; import Database from '../shared/services/Database'; import OneSignalUtils from '../shared/utils/OneSignalUtils'; -import { logMethodCall, getConsoleStyle } from '../shared/utils/utils'; +import { logMethodCall } from '../shared/utils/utils'; import OneSignalEvent from '../shared/services/OneSignalEvent'; import NotificationsNamespace from './NotificationsNamespace'; import CoreModule from '../core/CoreModule'; @@ -63,14 +63,7 @@ export default class OneSignal { private static async _initializeConfig(options: AppUserConfig) { const appConfig = await new ConfigManager().getAppConfig(options); - Log.debug( - `OneSignal: Final web app config: %c${JSON.stringify( - appConfig, - null, - 4, - )}`, - getConsoleStyle('code'), - ); + Log.debug('OneSignal: Final web app config:', appConfig); // TODO: environmentInfo is explicitly dependent on existence of OneSignal.config. Needs refactor. // Workaround to temp assign config so that it can be used in context. @@ -426,9 +419,8 @@ export default class OneSignal { LegacyManager.ensureBackwardsCompatibility(OneSignal); Log.info( - `%cOneSignal Web SDK loaded (version ${OneSignal._VERSION}, + `OneSignal Web SDK loaded (version ${OneSignal._VERSION}, ${SdkEnvironment.getWindowEnv().toString()} environment).`, - getConsoleStyle('bold'), ); Log.debug( `Current Page URL: ${ diff --git a/src/page/bell/Message.ts b/src/page/bell/Message.ts index 249634c09..3a0616894 100755 --- a/src/page/bell/Message.ts +++ b/src/page/bell/Message.ts @@ -1,6 +1,6 @@ import BrowserUtils from '../../shared/utils/BrowserUtils'; import Log from '../../shared/libraries/Log'; -import { delay, getConsoleStyle, nothing } from '../../shared/utils/utils'; +import { delay, nothing } from '../../shared/utils/utils'; import AnimatedElement from './AnimatedElement'; import Bell from './Bell'; @@ -37,10 +37,7 @@ export default class Message extends AnimatedElement { } display(type, content, duration = 0) { - Log.debug( - `Calling %cdisplay(${type}, ${content}, ${duration}).`, - getConsoleStyle('code'), - ); + Log.debug(`Calling display(${type}, ${content}, ${duration}).`); return (this.shown ? this.hide() : nothing()) .then(() => { this.content = BrowserUtils.decodeHtmlEntities(content); diff --git a/src/shared/context/Utils.ts b/src/shared/context/Utils.ts index 91dda45b7..24e9476cc 100644 --- a/src/shared/context/Utils.ts +++ b/src/shared/context/Utils.ts @@ -27,24 +27,6 @@ export class Utils { return indexOfAble.indexOf(match) !== -1; } - public static getConsoleStyle(style: string) { - if (style == 'code') { - return `padding: 0 1px 1px 5px;border: 1px solid #ddd;border-radius: 3px;font-family: Monaco,"DejaVu Sans Mono","Courier New",monospace;color: #444;`; - } else if (style == 'bold') { - return `font-weight: 600;color: rgb(51, 51, 51);`; - } else if (style == 'alert') { - return `font-weight: 600;color: red;`; - } else if (style == 'event') { - return `color: green;`; - } else if (style == 'postmessage') { - return `color: orange;`; - } else if (style == 'serviceworkermessage') { - return `color: purple;`; - } else { - return ''; - } - } - /** * Returns the current object without keys that have undefined values. * Regardless of whether the return result is used, the passed-in object is destructively modified. diff --git a/src/shared/helpers/HttpHelper.ts b/src/shared/helpers/HttpHelper.ts index c122e1e0c..77a58f437 100755 --- a/src/shared/helpers/HttpHelper.ts +++ b/src/shared/helpers/HttpHelper.ts @@ -6,7 +6,6 @@ import SubscriptionPopup from '../../page/modules/frames/SubscriptionPopup'; import Log from '../libraries/Log'; import SdkEnvironment from '../managers/SdkEnvironment'; import { WindowEnvironmentKind } from '../models/WindowEnvironmentKind'; -import { getConsoleStyle } from '../utils/utils'; import OneSignalEvent from '../services/OneSignalEvent'; declare let OneSignal: any; @@ -14,10 +13,7 @@ declare let OneSignal: any; export default class HttpHelper { // Http only - Only called from iframe's init.js static async initHttp(options: RemoteFrameOptions) { - Log.debug( - `Called %cinitHttp(${JSON.stringify(options, null, 4)})`, - getConsoleStyle('code'), - ); + Log.debug(`Called initHttp(${JSON.stringify(options, null, 4)})`); switch (SdkEnvironment.getWindowEnv()) { case WindowEnvironmentKind.OneSignalProxyFrame: diff --git a/src/shared/helpers/InitHelper.ts b/src/shared/helpers/InitHelper.ts index fcc5989ca..6280ab4fc 100755 --- a/src/shared/helpers/InitHelper.ts +++ b/src/shared/helpers/InitHelper.ts @@ -23,11 +23,7 @@ import { DynamicResourceLoader } from '../../page/services/DynamicResourceLoader import Database from '../services/Database'; import LimitStore from '../services/LimitStore'; import OneSignalUtils from '../utils/OneSignalUtils'; -import { - getConsoleStyle, - once, - triggerNotificationPermissionChanged, -} from '../utils/utils'; +import { once, triggerNotificationPermissionChanged } from '../utils/utils'; import Environment from './Environment'; import OneSignalEvent from '../services/OneSignalEvent'; import ProxyFrameHost from '../../page/modules/frames/ProxyFrameHost'; @@ -45,7 +41,7 @@ export default class InitHelper { /** Main methods */ public static async internalInit() { - Log.debug('Called %cinternalInit()', getConsoleStyle('code')); + Log.debug('Called internalInit()'); // Always check for an updated service worker await OneSignal.context.serviceWorkerManager.installWorker(); @@ -80,7 +76,7 @@ export default class InitHelper { } public static async sessionInit(): Promise { - Log.debug(`Called %csessionInit()`, getConsoleStyle('code')); + Log.debug(`Called sessionInit()`); if (OneSignal._sessionInitAlreadyRunning) { Log.debug( diff --git a/src/shared/helpers/MainHelper.ts b/src/shared/helpers/MainHelper.ts index cddce54f9..58e93919f 100755 --- a/src/shared/helpers/MainHelper.ts +++ b/src/shared/helpers/MainHelper.ts @@ -93,12 +93,7 @@ export default class MainHelper { const response = await fetch(url); const data = await response.json(); if (data.errors) { - Log.error( - `API call %c${url}`, - Utils.getConsoleStyle('code'), - 'failed with:', - data.errors, - ); + Log.error(`API call ${url}`, 'failed with:', data.errors); throw new Error('Failed to get notification icons.'); } return data; diff --git a/src/shared/services/OneSignalEvent.ts b/src/shared/services/OneSignalEvent.ts index 749813337..1120e4f3c 100755 --- a/src/shared/services/OneSignalEvent.ts +++ b/src/shared/services/OneSignalEvent.ts @@ -72,13 +72,9 @@ export default class OneSignalEvent { } if (displayData || displayData === false) { - Log.debug( - `(${env}) » %c${eventName}:`, - Utils.getConsoleStyle('event'), - displayData, - ); + Log.debug(`(${env}) » ${eventName}:`, displayData); } else { - Log.debug(`(${env}) » %c${eventName}`, Utils.getConsoleStyle('event')); + Log.debug(`(${env}) » ${eventName}`); } } diff --git a/src/shared/utils/OneSignalUtils.ts b/src/shared/utils/OneSignalUtils.ts index eff0a0266..ad2316c17 100644 --- a/src/shared/utils/OneSignalUtils.ts +++ b/src/shared/utils/OneSignalUtils.ts @@ -116,9 +116,7 @@ export class OneSignalUtils { public static logMethodCall(methodName: string, ...args: any[]) { return Log.debug( - `Called %c${methodName}(${args.map(Utils.stringify).join(', ')})`, - Utils.getConsoleStyle('code'), - '.', + `Called ${methodName}(${args.map(Utils.stringify).join(', ')})`, ); } diff --git a/src/shared/utils/utils.ts b/src/shared/utils/utils.ts index 832d973a1..528d637a9 100755 --- a/src/shared/utils/utils.ts +++ b/src/shared/utils/utils.ts @@ -211,10 +211,6 @@ export function hasCssClass( * }; */ -export function getConsoleStyle(style: string) { - return Utils.getConsoleStyle(style); -} - /** * Returns a promise for the setTimeout() method. * @param durationMs diff --git a/src/sw/serviceWorker/ServiceWorker.ts b/src/sw/serviceWorker/ServiceWorker.ts index fcaeebb52..d1b125b85 100755 --- a/src/sw/serviceWorker/ServiceWorker.ts +++ b/src/sw/serviceWorker/ServiceWorker.ts @@ -358,8 +358,7 @@ export class ServiceWorker { */ static onPushReceived(event: PushEvent): void { Log.debug( - `Called %conPushReceived(${JSON.stringify(event, null, 4)}):`, - Utils.getConsoleStyle('code'), + `Called onPushReceived(${JSON.stringify(event, null, 4)}):`, event, ); @@ -462,12 +461,7 @@ export class ServiceWorker { }; Log.debug( - `Called %csendConfirmedDelivery(${JSON.stringify( - notification, - null, - 4, - )})`, - Utils.getConsoleStyle('code'), + `Called sendConfirmedDelivery(${JSON.stringify(notification, null, 4)})`, ); await awaitableTimeout( @@ -745,8 +739,7 @@ export class ServiceWorker { */ static async displayNotification(notification: IMutableOSNotification) { Log.debug( - `Called %cdisplayNotification(${JSON.stringify(notification, null, 4)}):`, - Utils.getConsoleStyle('code'), + `Called displayNotification(${JSON.stringify(notification, null, 4)}):`, notification, ); @@ -854,8 +847,7 @@ export class ServiceWorker { */ static onNotificationClosed(event) { Log.debug( - `Called %conNotificationClosed(${JSON.stringify(event, null, 4)}):`, - Utils.getConsoleStyle('code'), + `Called onNotificationClosed(${JSON.stringify(event, null, 4)}):`, event, ); const notification = event.notification.data as IOSNotification; @@ -906,8 +898,7 @@ export class ServiceWorker { */ static async onNotificationClicked(event: NotificationEvent) { Log.debug( - `Called %conNotificationClicked(${JSON.stringify(event, null, 4)}):`, - Utils.getConsoleStyle('code'), + `Called onNotificationClicked(${JSON.stringify(event, null, 4)}):`, event, ); @@ -1198,8 +1189,7 @@ export class ServiceWorker { static async onPushSubscriptionChange(event: SubscriptionChangeEvent) { Log.debug( - `Called %conPushSubscriptionChange(${JSON.stringify(event, null, 4)}):`, - Utils.getConsoleStyle('code'), + `Called onPushSubscriptionChange(${JSON.stringify(event, null, 4)}):`, event, ); diff --git a/src/sw/webhooks/OSWebhookSender.ts b/src/sw/webhooks/OSWebhookSender.ts index 05ccee6f4..df4754692 100644 --- a/src/sw/webhooks/OSWebhookSender.ts +++ b/src/sw/webhooks/OSWebhookSender.ts @@ -31,7 +31,7 @@ export class OSWebhookSender { Log.debug( `Executing ${payload.event} webhook ${ isServerCorsEnabled ? 'with' : 'without' - } CORS %cPOST ${webhookTargetUrl}`, + } CORS POST ${webhookTargetUrl}`, payload, ); await fetch(webhookTargetUrl, fetchOptions);