Ameer Hamza
Ameer Hamza

Reputation: 87

How to disable Logs for flutter_sound package?

I'm using flutter_sound package for recording and playing audios. Default log level is pretty annoying.

I've tried

FlutterSoundRecorder myRecorder = FlutterSoundRecorder(logLevel: Level.debug);

but Level is undefined here. It's not present in flutter_sound package (flutter_sound is already imported).

import 'package:flutter_sound/flutter_sound.dart';

I'm unable to figure out how to import it? Version of flutter_sound package is

  flutter_sound: ^9.2.13

What am I doing wrong here?

Upvotes: 2

Views: 994

Answers (4)

3c71
3c71

Reputation: 4531

First you'll have to add logger dependencies in pubspec:

logger: ^1.4.0

Then in code, you can individually disable/reduce logging:

player.setLogLevel(Level.error);
recorder.setLogLevel(Level.error);

Upvotes: 0

okan
okan

Reputation: 934

You can change the log level of the flutter_sound package as follows:

  1. First, you need to add the logging package to your project by command:

    flutter pub add logger
    
  2. Then, import the Level enum by adding the following import statement:

    import 'package:logger/logger.dart';
    
  3. Finally, set the log level to the intended value in your code:

    final recorder = FlutterSoundRecorder(logLevel: Level.nothing);
    final player = FlutterSoundPlayer(logLevel: Level.nothing);
    

Upvotes: 1

Da  Lin
Da Lin

Reputation: 178

You can import logger

import 'package:logger/logger.dart';

Upvotes: 0

Sujan Gainju
Sujan Gainju

Reputation: 4769

As per flutter_sound doc, you can set loglevel as

await myRecorder.setLogLevel(Level.debug);

For detailed info, you can visit their documentation

Upvotes: 0

Related Questions