Skip to content

Implement an easily replaceable Printer for console #551

Closed

Description

@Razican

Current situation
We currently have the Console standard implemented, but we don't implement it with the common Logger, Printer and Formatter operations. This prevents crates using Boa from creating their own printers that will for example not print anything but save the result to a file or a database.

Proposed feature
We should implement an easily replaceable Printer that would either be passed to the Realm / Interpreter, so that by default, the console will work as it does now, but we should have a way of creating the console object to use a custom Printer.

How do we do this?
We should have a printer object that implements the Printer trait, which would be something like:

trait Printer {
    fn print(&mut self, logLevel: LogLevel, args: &[Value]);
}

Maybe the trait needs to be modified, and we would need a LogLevel enum, but I think the implementation should go in this direction. The idea behind having the logger use &mut self is because we might want a printer that stores the logs in memory, or in a buffer, or that uses Write to write to a log file.

What I'm not very sure is on what the options should be in the Printer. Maybe we can just skip that argument for now.

Activity

  1. added
    A-Enhancement
    R-Discussion
    C-Builtins
    A-API
    on Jul 8, 2020
  2. changed the title [-]Implement an easily replaceable Logger, Printer and Formatter for `console`[/-] [+]Implement an easily replaceable Printer for `console`[/+] on Jul 8, 2020
  3. locked and limited conversation to collaborators on Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-APIA-EnhancementC-BuiltinsR-Discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions