MOBILE-3833 core: Add cookie to force logs
parent
2103ad0c66
commit
09d9fab2bb
|
@ -23,7 +23,7 @@ import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreDatabaseTable } from '@classes/database/database-table';
|
import { CoreDatabaseTable } from '@classes/database/database-table';
|
||||||
import { asyncInstance } from '../utils/async-instance';
|
import { asyncInstance } from '../utils/async-instance';
|
||||||
import { CorePromisedValue } from '@classes/promised-value';
|
import { CorePromisedValue } from '@classes/promised-value';
|
||||||
import { CoreUtils } from './utils/utils';
|
import { CoreBrowser } from '@singletons/browser';
|
||||||
|
|
||||||
declare module '@singletons/events' {
|
declare module '@singletons/events' {
|
||||||
|
|
||||||
|
@ -195,11 +195,11 @@ export class CoreConfigProvider {
|
||||||
* Load development config overrides.
|
* Load development config overrides.
|
||||||
*/
|
*/
|
||||||
protected loadDevelopmentConfig(): void {
|
protected loadDevelopmentConfig(): void {
|
||||||
if (!CoreConstants.enableDevTools() || !CoreUtils.hasCookie('MoodleAppConfig')) {
|
if (!CoreConstants.enableDevTools() || !CoreBrowser.hasCookie('MoodleAppConfig')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.patchEnvironment(JSON.parse(CoreUtils.getCookie('MoodleAppConfig') ?? '{}'));
|
this.patchEnvironment(JSON.parse(CoreBrowser.getCookie('MoodleAppConfig') ?? '{}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,9 +16,9 @@ import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { SQLiteDB } from '@classes/sqlitedb';
|
import { SQLiteDB } from '@classes/sqlitedb';
|
||||||
import { SQLiteDBMock } from '@features/emulator/classes/sqlitedb';
|
import { SQLiteDBMock } from '@features/emulator/classes/sqlitedb';
|
||||||
|
import { CoreBrowser } from '@singletons/browser';
|
||||||
import { makeSingleton, SQLite, Platform } from '@singletons';
|
import { makeSingleton, SQLite, Platform } from '@singletons';
|
||||||
import { CoreAppProvider } from './app';
|
import { CoreAppProvider } from './app';
|
||||||
import { CoreUtils } from './utils/utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service allows interacting with the local database to store and retrieve data.
|
* This service allows interacting with the local database to store and retrieve data.
|
||||||
|
@ -36,7 +36,7 @@ export class CoreDbProvider {
|
||||||
* @returns Whether queries should be logged.
|
* @returns Whether queries should be logged.
|
||||||
*/
|
*/
|
||||||
loggingEnabled(): boolean {
|
loggingEnabled(): boolean {
|
||||||
return CoreUtils.hasCookie('MoodleAppDBLoggingEnabled') || CoreAppProvider.isAutomated();
|
return CoreBrowser.hasCookie('MoodleAppDBLoggingEnabled') || CoreAppProvider.isAutomated();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1765,34 +1765,6 @@ export class CoreUtilsProvider {
|
||||||
return CoreApp.isIOS() && openFileAction == OpenFileAction.OPEN_WITH;
|
return CoreApp.isIOS() && openFileAction == OpenFileAction.OPEN_WITH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether the given cookie is set.
|
|
||||||
*
|
|
||||||
* @param name Cookie name.
|
|
||||||
* @returns Whether the cookie is set.
|
|
||||||
*/
|
|
||||||
hasCookie(name: string): boolean {
|
|
||||||
return new RegExp(`(\\s|;|^)${name}=`).test(document.cookie ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read a cookie.
|
|
||||||
*
|
|
||||||
* @param name Cookie name.
|
|
||||||
* @return Cookie value.
|
|
||||||
*/
|
|
||||||
getCookie(name: string): string | null {
|
|
||||||
const cookies = (document.cookie ?? '').split(';').reduce((cookies, cookie) => {
|
|
||||||
const [name, value] = cookie.trim().split('=');
|
|
||||||
|
|
||||||
cookies[name] = value;
|
|
||||||
|
|
||||||
return cookies;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
return cookies[name] ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CoreUtils = makeSingleton(CoreUtilsProvider);
|
export const CoreUtils = makeSingleton(CoreUtilsProvider);
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helpers to interact with Browser APIs.
|
||||||
|
*/
|
||||||
|
export class CoreBrowser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the given cookie is set.
|
||||||
|
*
|
||||||
|
* @param name Cookie name.
|
||||||
|
* @returns Whether the cookie is set.
|
||||||
|
*/
|
||||||
|
static hasCookie(name: string): boolean {
|
||||||
|
return new RegExp(`(\\s|;|^)${name}=`).test(document.cookie ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a cookie.
|
||||||
|
*
|
||||||
|
* @param name Cookie name.
|
||||||
|
* @return Cookie value.
|
||||||
|
*/
|
||||||
|
static getCookie(name: string): string | null {
|
||||||
|
const cookies = (document.cookie ?? '').split(';').reduce((cookies, cookie) => {
|
||||||
|
const [name, value] = cookie.trim().split('=');
|
||||||
|
|
||||||
|
cookies[name] = value;
|
||||||
|
|
||||||
|
return cookies;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return cookies[name] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ import moment from 'moment';
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
|
|
||||||
import { CoreTime } from './time';
|
import { CoreTime } from './time';
|
||||||
|
import { CoreBrowser } from '@singletons/browser';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to warn that logs are disabled, called only once.
|
* Method to warn that logs are disabled, called only once.
|
||||||
|
@ -67,7 +68,10 @@ export class CoreLogger {
|
||||||
*/
|
*/
|
||||||
static getInstance(className: string): CoreLogger {
|
static getInstance(className: string): CoreLogger {
|
||||||
// Disable log on production and testing.
|
// Disable log on production and testing.
|
||||||
if (CoreConstants.BUILD.isProduction || CoreConstants.BUILD.isTesting) {
|
if (
|
||||||
|
!CoreBrowser.hasCookie('MoodleAppLoggingEnabled') &&
|
||||||
|
(CoreConstants.BUILD.isProduction || CoreConstants.BUILD.isTesting)
|
||||||
|
) {
|
||||||
if (CoreConstants.BUILD.isProduction) {
|
if (CoreConstants.BUILD.isProduction) {
|
||||||
warnLogsDisabled();
|
warnLogsDisabled();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue