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

Fileoutput/Multioutput is not writing the logs to file #156

Open
pushpacbasappa opened this issue May 8, 2024 · 0 comments
Open

Fileoutput/Multioutput is not writing the logs to file #156

pushpacbasappa opened this issue May 8, 2024 · 0 comments

Comments

@pushpacbasappa
Copy link

pushpacbasappa commented May 8, 2024

Hi
I am using MultiOutput to Log to multioutput location. Below is my code to Create logger

List<LogOutput> delegateList = List.empty(growable: true);
 for (var element in logUploadMechanism) {
   delegateList.add(getloggerDelegates(element));
 }
 MultiOutput output = MultiOutput(delegateList);
 logger = Logger(
     printer: LoggerMessager(), output:output);

LogOutput getloggerDelegates(delegateName) {
  switch (delegateName.toLowerCase()) {
    case CONSTANT_STRING_CONSOLE:
      return ConsoleLoggerDelegate();
    case CONSTANT_STRING_FILE:
      return FileLoggerDelegate(file: File("logs.txt"));
    case CONSTANT_STRING_AWS_FIREHOSE:
      return AWSFirehoseLoggerDelegate();
    default:
      return ConsoleLoggerDelegate();
  }
}

created the custom output class for each output method.
Here is my fileOutput class

class FileLoggerDelegate extends LogOutput {
  @override
  void output(OutputEvent event) {
    print("FileLoggerDelegate");
    var filePath = 'logs.txt';
    var file = File(filePath).openWrite(mode: FileMode.append);
    for (var line in event.lines) {
      file.writeln(line);
    }
    file.close();
  }
}

File is not creating and also logging is not happening. I have no clue what is going wrong. Suggestion would be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant