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

Feature request: Add name filter for log #280

Open
a1573595 opened this issue Nov 14, 2024 · 4 comments
Open

Feature request: Add name filter for log #280

a1573595 opened this issue Nov 14, 2024 · 4 comments
Labels
consideration Awaiting a decision on implementation core Related to core packages (talker, talker_logger, talker_flutter) enhancement New feature or request question Further information is requested

Comments

@a1573595
Copy link

a1573595 commented Nov 14, 2024

Is your feature request related to a problem? Please describe.
When there are various events in the log, it is not easy to check, refer to Proposal #279, add a filter with custom name to make customized Logger flexible.

Describe the solution you'd like
Add a filter to specify the name of the log to be output.

final talker = Talker(
    settings: const TalkerSettings(
      /// Add a custom filter
      nameFilterList : [ "Cloud message", "Google Analytics", ...],
      ...
    ),
    ///etc...
  );

Describe alternatives you've considered
As an alternative, I could manually add the filter for name or tag in the log message, but this becomes cumbersome and doesn't provide the same level of integration or convenience that a dedicated name parameter would offer.

Adding the ability to specify custom tag filters will allow for better log management, especially in large applications.

@Frezyx Frezyx added enhancement New feature or request consideration Awaiting a decision on implementation core Related to core packages (talker, talker_logger, talker_flutter) labels Nov 14, 2024
@Frezyx
Copy link
Owner

Frezyx commented Nov 17, 2024

Hello @a1573595 ! 👋
Right now this functionality included in TalkerFilter

You can provide any log titles or log types in TalkerFilter constructor and then talker will not show and store relevant logs.

final filter = BaseTalkerFilter(
    titles: ['Error'],
    types: [Exception],
);

final talker = Talker(filter: filter);
talker.info('Any info message'); // Do nothing

Does this solve your problem?

@Frezyx Frezyx added question Further information is requested consideration Awaiting a decision on implementation and removed consideration Awaiting a decision on implementation labels Nov 17, 2024
@a1573595
Copy link
Author

a1573595 commented Nov 18, 2024

Hello @a1573595 ! 👋 Right now this functionality included in TalkerFilter

You can provide any log titles or log types in TalkerFilter constructor and then talker will not show and store relevant logs.

final filter = BaseTalkerFilter(
    titles: ['Error'],
    types: [Exception],
);

final talker = Talker(filter: filter);
talker.info('Any info message'); // Do nothing

Does this solve your problem?

Is the filter title for the log level rather than the type of event? For example, I only want to track Bluetooth, which may contain multiple levels, such as info, warning, and error.

@Frezyx
Copy link
Owner

Frezyx commented Nov 20, 2024

Hello @a1573595 ! 👋 Right now this functionality included in TalkerFilter
You can provide any log titles or log types in TalkerFilter constructor and then talker will not show and store relevant logs.

final filter = BaseTalkerFilter(
    titles: ['Error'],
    types: [Exception],
);

final talker = Talker(filter: filter);
talker.info('Any info message'); // Do nothing

Does this solve your problem?

Is the filter title for the log level rather than the type of event? For example, I only want to track Bluetooth, which may contain multiple levels, such as info, warning, and error.

Yes, filter currently work with types and titles of logs.
For example you can show only your custom Bluetooth logs in console.

In this case you need to create custom log class
And send all Bluetooth logs with talker.logCustom() method

@Frezyx
Copy link
Owner

Frezyx commented Nov 20, 2024

@a1573595 you can use example code below:

class BluetoothLog extends TalkerLog {
  BluetoothLog(String message) : super(message);

  /// Your custom log title
  @override
  String get title => 'bluetooth';

  /// Your custom log color
  @override
  AnsiPen get pen => AnsiPen()..green();
}

void main() {
  final talker = Talker(
    filter: BaseTalkerFilter(
      types: [BluetoothLog], //or titles:['bluetooth']
    ),
  );
  talker.logCustom(BluetoothLog('Connected to device id: {deviceId}'));
  talker.info('Other logs');
}

Console output:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consideration Awaiting a decision on implementation core Related to core packages (talker, talker_logger, talker_flutter) enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants