Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up references to ConsoleLogger #12499

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
} from '../src/utils';
import { Reachability as ReachabilityNative } from '../src/Reachability/Reachability.native';
import { Reachability } from '../src/Reachability/Reachability';
import { ConsoleLogger as Logger } from '../src/Logger';
import { ConsoleLogger } from '../src/Logger';
import { DateUtils } from '../src/Signer/DateUtils';

Logger.LOG_LEVEL = 'DEBUG';
ConsoleLogger.LOG_LEVEL = 'DEBUG';

describe('Util', () => {
beforeEach(() => {});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Cache/StorageCache.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import { loadAsyncStorage } from '@aws-amplify/react-native';
import { ConsoleLogger as Logger } from '../Logger';
import { ConsoleLogger } from '../Logger';
import { defaultConfig } from './constants';
import { StorageCacheCommon } from './StorageCacheCommon';
import { Cache, CacheConfig } from './types';
import { getCurrentSizeKey, getCurrentTime } from './utils';

const logger = new Logger('StorageCache');
const logger = new ConsoleLogger('StorageCache');
const AsyncStorage = loadAsyncStorage();

/*
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Cache/StorageCache.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { ConsoleLogger as Logger } from '../Logger';
import { ConsoleLogger } from '../Logger';
import { KeyValueStorage } from '../storage/KeyValueStorage';
import { getLocalStorageWithFallback } from '../storage/utils';
import { defaultConfig } from './constants';
import { StorageCacheCommon } from './StorageCacheCommon';
import { Cache, CacheConfig } from './types';
import { getCurrentSizeKey, getCurrentTime } from './utils';

const logger = new Logger('Cache');
const logger = new ConsoleLogger('StorageCache');

/**
* Customized storage based on the SessionStorage or LocalStorage with LRU implemented
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Cache/StorageCacheCommon.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { ConsoleLogger as Logger } from '../Logger';
import { ConsoleLogger } from '../Logger';
import { KeyValueStorageInterface } from '../types';
import { currentSizeKey, defaultConfig } from './constants';
import { CacheConfig, CacheItem, CacheItemOptions } from './types';
import { getCurrentSizeKey, getCurrentTime, getByteLength } from './utils';
import { assert, CacheErrorCode } from './utils/errorHelpers';

const logger = new Logger('StorageCache');
const logger = new ConsoleLogger('StorageCache');

/**
* Initialization of the cache
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/Hub/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { ConsoleLogger as Logger } from '../Logger';
import { ConsoleLogger } from '../Logger';
import { NO_HUBCALLBACK_PROVIDED_EXCEPTION } from '../constants';
import { AmplifyError } from '../errors';
import {
Expand All @@ -21,7 +21,7 @@ export const AMPLIFY_SYMBOL = (
: '@@amplify_default'
) as Symbol;

const logger = new Logger('Hub');
const logger = new ConsoleLogger('Hub');

export class HubClass {
name: string;
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/I18n/I18n.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { ConsoleLogger as Logger } from '../Logger';
import { Amplify } from '../singleton';
import { ConsoleLogger } from '../Logger';
import { I18nConfig } from './types';

const logger = new Logger('I18n');
const logger = new ConsoleLogger('I18n');

/**
* Language translation utility.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/I18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import { I18n as I18nClass } from './I18n';

import { ConsoleLogger as Logger } from '../Logger';
import { ConsoleLogger } from '../Logger';
import { I18nConfig } from './types';
import { assert, I18nErrorCode } from './errorHelpers';

const logger = new Logger('I18n');
const logger = new ConsoleLogger('I18n');

let _config: I18nConfig = { language: null };
let _i18n: I18nClass | null = null;
Expand Down
37 changes: 14 additions & 23 deletions packages/core/src/Logger/ConsoleLogger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { LoggingProvider, InputLogEvent } from '../types';
import { InputLogEvent, Logger, LoggingProvider, LogType } from './types';
import { AWS_CLOUDWATCH_CATEGORY } from '../constants';
import { Logger } from './logger-interface';

const LOG_LEVELS: Record<string, number> = {
VERBOSE: 1,
Expand All @@ -13,35 +12,27 @@ const LOG_LEVELS: Record<string, number> = {
ERROR: 5,
};

export enum LOG_TYPE {
DEBUG = 'DEBUG',
ERROR = 'ERROR',
INFO = 'INFO',
WARN = 'WARN',
VERBOSE = 'VERBOSE',
}

/**
* Write logs
* @class Logger
*/
export class ConsoleLogger implements Logger {
name: string;
level: LOG_TYPE | string;
level: LogType | string;
private _pluggables: LoggingProvider[];
private _config?: object;

/**
* @constructor
* @param {string} name - Name of the logger
*/
constructor(name: string, level: LOG_TYPE | string = LOG_TYPE.WARN) {
constructor(name: string, level: LogType | string = LogType.WARN) {
this.name = name;
this.level = level;
this._pluggables = [];
}

static LOG_LEVEL = null;
static LOG_LEVEL: string | null = null;

_padding(n: number) {
return n < 10 ? '0' + n : '' + n;
Expand Down Expand Up @@ -70,10 +61,10 @@ export class ConsoleLogger implements Logger {
* Write log
* @method
* @memeberof Logger
* @param {LOG_TYPE|string} type - log type, default INFO
* @param {LogType|string} type - log type, default INFO
* @param {string|object} msg - Logging message or object
*/
_log(type: LOG_TYPE | string, ...msg: any) {
_log(type: LogType | string, ...msg: any) {
let logger_level_name = this.level;
if (ConsoleLogger.LOG_LEVEL) {
logger_level_name = ConsoleLogger.LOG_LEVEL;
Expand All @@ -89,10 +80,10 @@ export class ConsoleLogger implements Logger {
}

let log = console.log.bind(console);
if (type === LOG_TYPE.ERROR && console.error) {
if (type === LogType.ERROR && console.error) {
log = console.error.bind(console);
}
if (type === LOG_TYPE.WARN && console.warn) {
if (type === LogType.WARN && console.warn) {
log = console.warn.bind(console);
}

Expand Down Expand Up @@ -130,7 +121,7 @@ export class ConsoleLogger implements Logger {
* @param {string|object} msg - Logging message or object
*/
log(...msg: any) {
this._log(LOG_TYPE.INFO, ...msg);
this._log(LogType.INFO, ...msg);
}

/**
Expand All @@ -140,7 +131,7 @@ export class ConsoleLogger implements Logger {
* @param {string|object} msg - Logging message or object
*/
info(...msg: any) {
this._log(LOG_TYPE.INFO, ...msg);
this._log(LogType.INFO, ...msg);
}

/**
Expand All @@ -150,7 +141,7 @@ export class ConsoleLogger implements Logger {
* @param {string|object} msg - Logging message or object
*/
warn(...msg: any) {
this._log(LOG_TYPE.WARN, ...msg);
this._log(LogType.WARN, ...msg);
}

/**
Expand All @@ -160,7 +151,7 @@ export class ConsoleLogger implements Logger {
* @param {string|object} msg - Logging message or object
*/
error(...msg: any) {
this._log(LOG_TYPE.ERROR, ...msg);
this._log(LogType.ERROR, ...msg);
}

/**
Expand All @@ -170,7 +161,7 @@ export class ConsoleLogger implements Logger {
* @param {string|object} msg - Logging message or object
*/
debug(...msg: any) {
this._log(LOG_TYPE.DEBUG, ...msg);
this._log(LogType.DEBUG, ...msg);
}

/**
Expand All @@ -180,7 +171,7 @@ export class ConsoleLogger implements Logger {
* @param {string|object} msg - Logging message or object
*/
verbose(...msg: any) {
this._log(LOG_TYPE.VERBOSE, ...msg);
this._log(LogType.VERBOSE, ...msg);
}

addPluggable(pluggable: LoggingProvider) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export { ConsoleLogger, LOG_TYPE } from './ConsoleLogger';
export { ConsoleLogger } from './ConsoleLogger';
12 changes: 0 additions & 12 deletions packages/core/src/Logger/logger-interface.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ export interface LoggingProvider {
// take logs and push to provider
pushLogs(logs: InputLogEvent[]): void;
}

export interface Logger {
debug(msg: string): void;
info(msg: string): void;
warn(msg: string): void;
error(msg: string): void;
addPluggable(pluggable: LoggingProvider): void;
}

export enum LogType {
DEBUG = 'DEBUG',
ERROR = 'ERROR',
INFO = 'INFO',
WARN = 'WARN',
VERBOSE = 'VERBOSE',
}
4 changes: 2 additions & 2 deletions packages/core/src/Reachability/Reachability.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
import { Observable } from 'rxjs';
import { loadNetInfo } from '@aws-amplify/react-native';
import { ConsoleLogger as Logger } from '../Logger';
import { ConsoleLogger } from '../Logger';
import { NetworkStatus } from './types';

const logger = new Logger('Reachability', 'DEBUG');
const logger = new ConsoleLogger('Reachability', 'DEBUG');

export class Reachability {
networkMonitor(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/ServiceWorker/ServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { ConsoleLogger as Logger } from '../Logger';
import { ConsoleLogger } from '../Logger';
import { isBrowser } from '../utils';
import { AmplifyError } from '../errors';
import { assert, ServiceWorkerErrorCode } from './errorHelpers';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class ServiceWorkerClass {
private _subscription?: PushSubscription;

// The AWS Amplify logger
private _logger: Logger = new Logger('ServiceWorker');
private _logger: ConsoleLogger = new ConsoleLogger('ServiceWorker');

constructor() {}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/parseAWSExports.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { ConsoleLogger as Logger } from './Logger';
import { ConsoleLogger } from './Logger';
import {
OAuthConfig,
AuthConfigUserAttributes,
OAuthProvider,
} from './singleton/Auth/types';
import { ResourcesConfig } from './singleton/types';

const logger = new Logger('parseAWSExports');
const logger = new ConsoleLogger('parseAWSExports');

const authTypeMapping: Record<any, any> = {
API_KEY: 'apiKey',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { ConsoleLogger as Logger } from '../../../Logger';
import { ConsoleLogger } from '../../../Logger';
import {
EventsBatch,
putEvents,
Expand All @@ -17,7 +17,7 @@ import {
import { AuthSession } from '../../../singleton/Auth/types';
import { isAppInForeground } from './isAppInForeground';

const logger = new Logger('PinpointEventBuffer');
const logger = new ConsoleLogger('PinpointEventBuffer');
const RETRYABLE_CODES = [429, 500];
const ACCEPTED_CODES = [202];

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

export * from './core';
export * from './errors';
export * from './logging';
export * from './storage';
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
// @ts-ignore: missing type definition
import { Platform, Dimensions } from 'react-native';
import { ConsoleLogger as Logger } from '../../Logger';
import { ConsoleLogger } from '../../Logger';

const logger = new Logger('DeviceInfo');
const logger = new ConsoleLogger('getClientInfo');

export const getClientInfo = () => {
const dim = Dimensions.get('screen');
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/getClientInfo/getClientInfo.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
// @ts-ignore: missing type definition
import { Platform, Dimensions } from 'react-native';
import { ConsoleLogger as Logger } from '../../Logger';
import { ConsoleLogger } from '../../Logger';

const logger = new Logger('DeviceInfo');
const logger = new ConsoleLogger('getClientInfo');

export const getClientInfo = () => {
const dim = Dimensions.get('screen');
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/getClientInfo/getClientInfo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { ConsoleLogger as Logger } from '../../Logger';
import { ConsoleLogger } from '../../Logger';

const logger = new Logger('ClientDevice_Browser');
const logger = new ConsoleLogger('getClientInfo');

export function getClientInfo() {
if (typeof window === 'undefined') {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/retry/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import { DelayFunction } from '../../types';
import { ConsoleLogger as Logger } from '../../Logger/ConsoleLogger';
import { ConsoleLogger } from '../../Logger/ConsoleLogger';
import { isNonRetryableError } from './isNonRetryableError';

const logger = new Logger('Util');
const logger = new ConsoleLogger('retryUtil');

/**
* @private
Expand Down
Loading
Loading