From a2eb6ff4af23050875ba1d521a360e209c0a68d6 Mon Sep 17 00:00:00 2001 From: wpp <58198665+879356503@users.noreply.github.com> Date: Thu, 18 Sep 2025 17:01:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Logger=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fluentbloglibrary/Index.ets | 4 +- .../src/main/ets/utils/AVPlayerUtil.ets | 6 +-- .../src/main/ets/utils/BreakpointSystem.ets | 4 +- .../src/main/ets/utils/Logger.ets | 45 +++++++++++++++++++ .../src/main/ets/utils/WindowUtil.ets | 14 +++--- .../main/ets/viewmodel/BasicDataSource.ets | 6 +-- .../main/ets/entryability/EntryAbility.ets | 17 ++++--- 7 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 fluentbloglibrary/src/main/ets/utils/Logger.ets diff --git a/fluentbloglibrary/Index.ets b/fluentbloglibrary/Index.ets index de0da8a..6e538f0 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 f391ae4..08943d6 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 53303c8..637e3b0 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 0000000..74b07d4 --- /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('[ContinuePublish]'); \ 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 ad3f39a..5b8360e 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 90ba74d..aaebf88 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 a726f4d..3370f96 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 -- Gitee From 38b8a8eb988ac0619fae175f13871a9a7cb7563c Mon Sep 17 00:00:00 2001 From: wpp <58198665+879356503@users.noreply.github.com> Date: Thu, 18 Sep 2025 17:04:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Logger=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fluentbloglibrary/src/main/ets/utils/Logger.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluentbloglibrary/src/main/ets/utils/Logger.ets b/fluentbloglibrary/src/main/ets/utils/Logger.ets index 74b07d4..3e9ef03 100644 --- a/fluentbloglibrary/src/main/ets/utils/Logger.ets +++ b/fluentbloglibrary/src/main/ets/utils/Logger.ets @@ -42,4 +42,4 @@ class Logger { } } -export default new Logger('[ContinuePublish]'); \ No newline at end of file +export default new Logger('[FluentBlog]'); \ No newline at end of file -- Gitee