From ce9fbf72cd4d7f2aff206753f79a86d1277850b7 Mon Sep 17 00:00:00 2001 From: LeadcodeDev Date: Sat, 6 Jan 2024 20:53:00 +0100 Subject: [PATCH] feat(api): implemented logger --- lib/application/kernel/kernel.dart | 12 +++++++++--- lib/domains/data/packets/ready_packet.dart | 8 +++++++- lib/domains/shared/types/kernel_contract.dart | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/application/kernel/kernel.dart b/lib/application/kernel/kernel.dart index bd06de18..fcc75f85 100644 --- a/lib/application/kernel/kernel.dart +++ b/lib/application/kernel/kernel.dart @@ -1,6 +1,7 @@ import 'package:mineral/application/http/header.dart'; import 'package:mineral/application/http/http_client.dart'; import 'package:mineral/application/http/http_client_config.dart'; +import 'package:mineral/application/logger/logger.dart'; import 'package:mineral/domains/data/data_listener.dart'; import 'package:mineral/domains/data/memory/memory_storage.dart'; import 'package:mineral/domains/data/packets/guild_create_packet.dart'; @@ -17,13 +18,16 @@ final class Kernel implements KernelContract { @override final ShardingConfigContract config; + @override + final LoggerContract logger; + @override final HttpClientContract httpClient; @override final DataListenerContract dataListener; - Kernel({required this.httpClient, required this.config, required this.dataListener}) { + Kernel({required this.logger, required this.httpClient, required this.config, required this.dataListener}) { httpClient.config.headers.addAll([ Header.authorization('Bot ${config.token}'), ]); @@ -60,12 +64,14 @@ final class Kernel implements KernelContract { final shardConfig = ShardingConfig(token: token, intent: intent, version: shardVersion); + final LoggerContract logger = Logger(); + final MemoryStorageContract storage = MemoryStorage(); final DataListenerContract dataListener = DataListener() - ..listenPacketClass(ReadyPacket(storage)) + ..listenPacketClass(ReadyPacket(logger, storage)) ..listenPacketClass(MessageCreatePacket(storage)) ..listenPacketClass(GuildCreatePacket(storage)); - return Kernel(httpClient: http, config: shardConfig, dataListener: dataListener); + return Kernel(logger: logger, httpClient: http, config: shardConfig, dataListener: dataListener); } } diff --git a/lib/domains/data/packets/ready_packet.dart b/lib/domains/data/packets/ready_packet.dart index fa5698cc..c3bcc424 100644 --- a/lib/domains/data/packets/ready_packet.dart +++ b/lib/domains/data/packets/ready_packet.dart @@ -1,4 +1,7 @@ +import 'dart:convert'; + import 'package:mineral/api/common/bot.dart'; +import 'package:mineral/application/logger/logger.dart'; import 'package:mineral/domains/data/internal_event_params.dart'; import 'package:mineral/domains/data/memory/memory_storage.dart'; import 'package:mineral/domains/data/types/listenable_packet.dart'; @@ -9,15 +12,18 @@ final class ReadyPacket implements ListenablePacket { @override PacketType get event => PacketType.ready; + final LoggerContract logger; final MemoryStorageContract storage; - const ReadyPacket(this.storage); + const ReadyPacket(this.logger, this.storage); @override void listen(Map payload) { final { 'message': ShardMessage message, 'dispatch': Function(InternalEventParams) dispatch } = payload; final client = Bot.fromJson(message.payload); + + logger.trace(jsonEncode(message.payload)); dispatch(InternalEventParams(event.toString(), [client])); } } diff --git a/lib/domains/shared/types/kernel_contract.dart b/lib/domains/shared/types/kernel_contract.dart index a0c25509..21ccb7fc 100644 --- a/lib/domains/shared/types/kernel_contract.dart +++ b/lib/domains/shared/types/kernel_contract.dart @@ -1,4 +1,5 @@ import 'package:mineral/application/http/http_client.dart'; +import 'package:mineral/application/logger/logger.dart'; import 'package:mineral/domains/data/data_listener.dart'; import 'package:mineral/domains/wss/shard.dart'; import 'package:mineral/domains/wss/sharding_config.dart'; @@ -8,6 +9,8 @@ abstract interface class KernelContract { ShardingConfigContract get config; + LoggerContract get logger; + HttpClientContract get httpClient; DataListenerContract get dataListener;