refactor(log): improved logging with instance level logging enable feature.#136
Conversation
|
|
||
| // Log module information | ||
| messageString += '\n\tModules:'; | ||
| messageString += |
There was a problem hiding this comment.
I see that each module could override toString() method, which should make creating a final String representation of a PubNub object a bit easier:
messageString += pubnub.networking.toString()
messageString += pubnub.parser.toString()
messageString += pubnub.crypto.toString()
There was a problem hiding this comment.
👍🏻
applied mentioned approach at 65e82a7
| for (var i = 0; i < allKeysets.length; i++) { | ||
| var keyset = allKeysets[i]; | ||
| var name = keysetNames[i]; | ||
| messageString += '\n\t $name:'; |
There was a problem hiding this comment.
Perhaps the same as mentioned above can be applied to custom Keyset type:
| } else if (detailsType == LogEventDetailsType.networkRequestInfo) { | ||
| var requestMap = details as Map<String, dynamic>; | ||
|
|
||
| for (var entry in requestMap.entries) { |
There was a problem hiding this comment.
It works, although I do think this may be challenging to maintain in the long-run. Do you have the ability to introduce and log more abstract types, let's say, NetworkRequest or NetworkResponse? They can have properties specific to request and response, respectively, and override toString() method. Then, you could always call .toString() to create your messageString regardless of the passed object.
| } | ||
|
|
||
| /// Set up global logging that will be available throughout the entire SDK | ||
| static void _setupGlobalLogging( |
There was a problem hiding this comment.
Let's leave it as it is now because of the scope of the change; however, it would be great to consider dependency injection tools like GetIt or even a custom one in the long-run
There was a problem hiding this comment.
Agree! There is scope for enhancement. And this can be part of a dedicated task which can deal with it along with other impacted components.
There was a problem hiding this comment.
@jguz-pubnub now with dff7080 change. We have a logging configuration injectable
Now the initialisation looks like:
var pubnub = PubNub(
defaultKeyset: Keyset(
subscribeKey: 'sub-key',
publishKey: 'pub-key',
userId: UserId('test-user')),
logging: LoggingConfiguration(
logLevel: Level.all, // Enable logging at all level
// optional other configurations.
loggerName: 'test-pubnub',
logToConsole: false,
),
);| bool includeMessageType = true, | ||
| bool includeCustomMessageType = false, | ||
| bool includeUUID = true}) async { | ||
| _logger.info('Fetch messages API call'); |
There was a problem hiding this comment.
I assume any method like _logger object, like .info, or .fine produce a LogRecord you can listen to or print it to the console. Is this record's format compliant with the format we have in ADR? For example:
"${timestamp} PubNub-${instanceId} Debug ${callsite} Some message"
There was a problem hiding this comment.
here 'Fetch messages API call' is just a part of a message.
The final log information in it's string format (in default format) looks like this:
2025-08-05 07:37:29.303300 info PubNub-49078.pubnub.dx.batch: Fetch messages API call
…dule and types information in readable fomat and cleanup the logging implementation to use toString() methods on those modules.
…isable retry for subscribe test(retry_policy): added tests for retry policy refactor: retry policy applicable to subscribe only
|
@jakub-grzesiowski there is missing support for disabling retry. So adbfbd5 contains changes to handle disabling retry scenario with |
| if (details is Response) { | ||
| messageString += details.toString(); | ||
| } else if (details is Map) { | ||
| var detailsMap = details as Map<String, dynamic>; |
There was a problem hiding this comment.
What happens if you call details.toString() regardless of the underlying object type? Why don't we want to print the whole Map object and select a few keys only to be printed out?
There was a problem hiding this comment.
Agree!! The issue we have here in this specific case is:
We need to print request url along with response details and in networking module we are missing URL in case of dart:io 's HttpResponse..
However once we have more standard Networking, We can have more cleaner version here
|
|
||
| late final ILogger __logger; | ||
| Fiber(this._core, {required this.action}) : id = _id++ { | ||
| Fiber(this._core, {required this.action, RequestType? requestType}) |
There was a problem hiding this comment.
I see we could apply dart format to update our code to follow the Dart formatting guidelines and enable it to run on each save. You don't have to do it now, I'm thinking about creating a story for that to see what's the outcome
There was a problem hiding this comment.
before committing I ran dart format. Strange that this isn't formatted! Looking into it
…guration for logging at instance level. Removed static methods from default file to have a clean approach.
|
@pubnub-release-bot release dart as v6.0.0 |
|
🛑 Build failed. Please check release build for details 🛑 |
|
Just linking this issue to this PR: #137 |
feature: support for disabling retry.
Added support for
RetryPolicy.none()to disable retry for subscription.BREAKING CHANGES: The default retry policy has been changed from applying to all operations to now applying only to the subscription feature, with the
exponentialpolicy set by default.refactor: improved logging in the library
Enhanced logging using standardized logging practices.