diff --git a/fluentbloglibrary/Index.ets b/fluentbloglibrary/Index.ets index de0da8af49fd247fe7521148a981387ea4fcce5c..6e538f0cfb273c5dfc66d613da05b673a9815a93 100644 --- a/fluentbloglibrary/Index.ets +++ b/fluentbloglibrary/Index.ets @@ -1,3 +1,5 @@ export { FluentBlogComponent } from './src/main/ets/component/FluentBlogComponent'; -export { FluentBlogController } from './src/main/ets/FluentBlogController'; \ No newline at end of file +export { FluentBlogController } from './src/main/ets/FluentBlogController'; + +export { default as Logger } from './src/main/ets/utils/Logger'; \ No newline at end of file diff --git a/fluentbloglibrary/src/main/ets/utils/AVPlayerUtil.ets b/fluentbloglibrary/src/main/ets/utils/AVPlayerUtil.ets index f391ae4cdec0abcf791a92913c20f25da776a365..08943d67f481d021618f1c13a6792b5318454958 100644 --- a/fluentbloglibrary/src/main/ets/utils/AVPlayerUtil.ets +++ b/fluentbloglibrary/src/main/ets/utils/AVPlayerUtil.ets @@ -15,7 +15,7 @@ import { common } from '@kit.AbilityKit'; import { media } from '@kit.MediaKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; +import Logger from './Logger'; const TAG: string = '[AVPlayerItem]' @@ -87,7 +87,7 @@ export class AVPlayerUtil { this.avPlayer.fdSrc = avFileDescriptor; this.avPlayer.prepare(); } catch (error) { - hilog.error(0x0000, TAG, `avPlayerPlay fail, error code: ${error.code}, message: ${error.message}`); + Logger.error(TAG, `avPlayerPlay fail, error code: ${error.code}, message: ${error.message}`); } } @@ -95,7 +95,7 @@ export class AVPlayerUtil { try { this.avPlayer?.release(); } catch (error) { - hilog.error(0x0000, TAG, `avPlayerPlay release fail, error code: ${error.code}, message: ${error.message}`); + Logger.error(TAG, `avPlayerPlay release fail, error code: ${error.code}, message: ${error.message}`); } } } \ No newline at end of file diff --git a/fluentbloglibrary/src/main/ets/utils/BreakpointSystem.ets b/fluentbloglibrary/src/main/ets/utils/BreakpointSystem.ets index 53303c80790e54b438aec632d0b5d777489b4b2f..637e3b09bcad8f75d77c5540e2d0dde0a135eece 100644 --- a/fluentbloglibrary/src/main/ets/utils/BreakpointSystem.ets +++ b/fluentbloglibrary/src/main/ets/utils/BreakpointSystem.ets @@ -15,8 +15,8 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { Constants } from '../common/Constants'; +import Logger from './Logger'; const TAG: string = '[BreakpointSystem]'; @@ -114,7 +114,7 @@ export class BreakpointSystem { this.updateCurrentBreakpoint(widthBp); } catch (error) { const err: BusinessError = error as BusinessError; - hilog.error(0x0000, TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); + Logger.error(TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); } } } \ No newline at end of file diff --git a/fluentbloglibrary/src/main/ets/utils/Logger.ets b/fluentbloglibrary/src/main/ets/utils/Logger.ets new file mode 100644 index 0000000000000000000000000000000000000000..3e9ef0331aabb6834f59fb6d2f57edde1ffabc2b --- /dev/null +++ b/fluentbloglibrary/src/main/ets/utils/Logger.ets @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + + public constructor(prefix: string) { + this.prefix = prefix; + this.domain = 0x0000; + } + + public debug(...args: Object[]): void { + hilog.debug(this.domain, this.prefix, this.format, args); + } + + public info(...args: Object[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + public warn(...args: Object[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + public error(...args: Object[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + +export default new Logger('[FluentBlog]'); \ No newline at end of file diff --git a/fluentbloglibrary/src/main/ets/utils/WindowUtil.ets b/fluentbloglibrary/src/main/ets/utils/WindowUtil.ets index ad3f39a10bd2743216eb8c897e4c140da0135eee..5b8360e86b60408e5cb40279f7b0ece76ae7f431 100644 --- a/fluentbloglibrary/src/main/ets/utils/WindowUtil.ets +++ b/fluentbloglibrary/src/main/ets/utils/WindowUtil.ets @@ -15,9 +15,9 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { Constants } from '../common/Constants'; import { BreakpointSystem } from './BreakpointSystem'; +import Logger from './Logger'; const TAG: string = '[WindowUtil]'; @@ -30,7 +30,7 @@ export class WindowUtil { WindowUtil.registerBreakPoint(WindowUtil.windowClass); WindowUtil.requestFullScreen(); } catch (err) { - hilog.error(0x0000, TAG, `WindowUtil initialize failed. Cause: ${err.code} ${err.message}`); + Logger.error(TAG, `WindowUtil initialize failed. Cause: ${err.code} ${err.message}`); } } @@ -45,7 +45,7 @@ export class WindowUtil { }); } catch (e) { const error = e as BusinessError; - hilog.error(0x0000, TAG, + Logger.error(TAG, `Get windowAvoidArea or Register windowSizeChange failed. code: ${error.code}, message: ${error.message}`); } } @@ -58,7 +58,7 @@ export class WindowUtil { WindowUtil.windowClass?.getUIContext().px2vp(area.topRect.height)); } } catch (error) { - hilog.error(0x0000, TAG, '%{public}s', + Logger.error(TAG, '%{public}s', `Get windowAvoidArea or Register windowSizeChange failed. code: ${(error as BusinessError).code} message is ${(error as BusinessError).message}`); } } @@ -68,13 +68,13 @@ export class WindowUtil { try { const promise: Promise | undefined = WindowUtil.windowClass?.setWindowLayoutFullScreen(true); promise?.then(() => { - hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); + Logger.info(TAG, 'Succeeded in setting the window layout to full-screen mode.'); }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, + Logger.error(TAG, `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); }); } catch { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); + Logger.error(TAG, 'Failed to set the window layout to full-screen mode. '); } } } \ No newline at end of file diff --git a/fluentbloglibrary/src/main/ets/viewmodel/BasicDataSource.ets b/fluentbloglibrary/src/main/ets/viewmodel/BasicDataSource.ets index 90ba74d1fe2ddf9742a112b552631420e636f017..aaebf88c8ce31f6c5ce4ed30682d5e90b00f7236 100644 --- a/fluentbloglibrary/src/main/ets/viewmodel/BasicDataSource.ets +++ b/fluentbloglibrary/src/main/ets/viewmodel/BasicDataSource.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { hilog } from '@kit.PerformanceAnalysisKit'; +import Logger from '../utils/Logger'; import ButtonUnitItem from './ButtonUnitItem'; import SampleUnitItem from './SampleUnitItem'; @@ -64,7 +64,7 @@ class BasicDataSource implements IDataSource { registerDataChangeListener(listener: DataChangeListener): void { if (this.listeners.indexOf(listener) < 0) { - hilog.info(0x0000, TAG, '%{public}s', 'add listener'); + Logger.info(TAG, 'add listener'); this.listeners.push(listener); } } @@ -72,7 +72,7 @@ class BasicDataSource implements IDataSource { unregisterDataChangeListener(listener: DataChangeListener): void { const pos = this.listeners.indexOf(listener); if (pos >= 0) { - hilog.info(0x0000, TAG, '%{public}s', 'remove listener'); + Logger.info(TAG, 'remove listener'); this.listeners.splice(pos, 1); } } diff --git a/fluentblogsample/src/main/ets/entryability/EntryAbility.ets b/fluentblogsample/src/main/ets/entryability/EntryAbility.ets index a726f4d40c5dd7ecb777537266194739a0f3ec68..3370f964cd623948fe303317126c3017ef3fcf65 100644 --- a/fluentblogsample/src/main/ets/entryability/EntryAbility.ets +++ b/fluentblogsample/src/main/ets/entryability/EntryAbility.ets @@ -15,41 +15,40 @@ import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; -import { FluentBlogController } from '@ohos_samples/fluentbloglibrary'; +import { FluentBlogController, Logger } from '@ohos_samples/fluentbloglibrary'; const TAG: string = '[EntryAbility]' export default class EntryAbility extends UIAbility { onCreate(): void { - hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); + Logger.info(TAG, '%{public}s', 'Ability onCreate'); } onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability - hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); + Logger.info(TAG, '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err, _) => { if (err.code) { - hilog.error(0x0000, TAG, 'Failed to load the content. Cause:', err.message); + Logger.error(TAG, 'Failed to load the content. Cause:', err.message); return; } FluentBlogController.initWindowConfig(windowStage); - hilog.info(0x0000, TAG, '%{public}s', 'Succeeded in loading the content'); + Logger.info(TAG, '%{public}s', 'Succeeded in loading the content'); }); } onWindowStageDestroy(): void { // Main window is destroyed, release UI related resources - hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + Logger.info(TAG, '%{public}s', 'Ability onWindowStageDestroy'); } onForeground(): void { // Ability has brought to foreground - hilog.info(0x0000, TAG, '%{public}s', 'Ability onForeground'); + Logger.info(TAG, '%{public}s', 'Ability onForeground'); } onBackground(): void { // Ability has back to background - hilog.info(0x0000, TAG, '%{public}s', 'Ability onBackground'); + Logger.info(TAG, '%{public}s', 'Ability onBackground'); } } \ No newline at end of file