Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

[NEW FEATURE] Setting custom logger Formatter #1889

Closed
mvlabat opened this issue Aug 18, 2019 · 2 comments
Closed

[NEW FEATURE] Setting custom logger Formatter #1889

mvlabat opened this issue Aug 18, 2019 · 2 comments
Labels
diff: easy Achievable by a single junior developer with a bit of guidance. pri: normal An issue that is causing a noticeable impact, but can be worked around team: engine type: feature A request for a new feature.

Comments

@mvlabat
Copy link
Member

mvlabat commented Aug 18, 2019

Description

I would like to use a custom logger formatter in my project. I have several binaries producing output to the same stdout (a client and a server as a child-process in my case), and I'd like to distinguish their output. Like this, for instance:

[INFO][SERVER][amethyst::app]

What problem does this solve? What need does it fill?

The only way I've found to accomplish this is to construct fern::Dispatch manually and apply it as a global logger, skipping Amethyst logger. I think it's quite easy to provide an API for passing custom formatter, so users don't have to construct the dispatcher manually.

Describe the solution you'd like

We could provide an alternative constructor that would allow passing both LoggerConfig and a formatter function.

@mvlabat mvlabat added status: needs triage type: feature A request for a new feature. labels Aug 18, 2019
@distransient distransient added diff: easy Achievable by a single junior developer with a bit of guidance. pri: normal An issue that is causing a noticeable impact, but can be worked around status: discussing team: engine and removed status: needs triage labels Aug 21, 2019
@nalshihabi
Copy link
Contributor

Hello, I am new here but I believe I can tackle this feature.

bors bot added a commit that referenced this issue Sep 3, 2019
1915: [FEATURE] Custom Logger Formatter r=azriel91,distransient a=nalshihabi

Implements #1889 

## Description

Add a custom log formatter option to the Amethyst logger so that instead of setting up their own logger to use their own formatting, a developer using Amethyst can just pass in their own formatter to the Amethyst logger.

## Additions

- `Logger::new_formatter`: a different constructor for Amethyst logger where a custom formatter can be passed as a parameter.
- `Logger::from_config_formatter`: a different function for the Logger for starting a new Logger with a config and a formatter.
- `Logger::new_with_config`: helper function that much of the functionality of `Logger::from_config` was moved into from `Logger::from_config` in order to allow for the functionality to be reused easily by `Logger::from_config_formatter`.

## Removals

None

## Modifications

- `Logger::from_config`: Changed to just call `Logger::from_config_formatter` with valid parameters for the helper function.

## PR Checklist

By placing an x in the boxes I certify that I have:

- [ ] Updated the content of the book if this PR would make the book outdated.
- [ ] Added a changelog entry if this will impact users, or modified more than 5 lines of Rust that wasn't a doc comment.
- [ ] Added unit tests for new code added in this PR.
- [x] Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.

If this modified or created any rs files:

- [x] Ran `cargo +stable fmt --all`
- [x] Ran `cargo clippy --all --features "empty"`
- [x] Ran `cargo test --all --features "empty"`


Co-authored-by: Noah AL-Shihabi <noahshihabi@gmail.com>
bors bot added a commit that referenced this issue Sep 3, 2019
1912: Feature/run setup fn before systems r=distransient a=azriel91

## Description

In `amethyst_test`, changed `AmethystApplication::with_setup` to run before the dispatcher. This allows resources to be computed and inserted from other resources in the `World`.

Previously, if a `System` had `ReadExpect<'_, T>`, and `T ` needed to be computed from the `World`, it was impossible to insert the resource before the system runs.

## Modifications

* `AmethystApplication::with_setup` now takes in `FnOnce(&mut World) + Send + 'static`.
* `AmethystApplication::with_setup` runs the function before the dispatcher.

## PR Checklist

By placing an x in the boxes I certify that I have:

- [x] Updated the content of the book if this PR would make the book outdated.
- [x] Added a changelog entry if this will impact users, or modified more than 5 lines of Rust that wasn't a doc comment.
- [x] Added unit tests for new code added in this PR.
- [x] Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.

If this modified or created any rs files:

- [x] Ran `cargo +stable fmt --all`
- [x] Ran `cargo clippy --all --features "empty"`
- [x] Ran `cargo test --all --features "empty"`


1913: Fix copy/paste error in formats.rs r=azriel91 a=crsaracco

## Description

Fix a copy/paste error in the comments of `formats.rs`

## PR Checklist

By placing an x in the boxes I certify that I have:

- [x] Updated the content of the book if this PR would make the book outdated.
   - Slight comment fix, book is not outdated
- [x] Added a changelog entry if this will impact users, or modified more than 5 lines of Rust that wasn't a doc comment.
   - Does not apply.
- [x] Added unit tests for new code added in this PR.
   - No new code.
- [x] Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.

If this modified or created any rs files:

- [ ] Ran `cargo +stable fmt --all`
- [ ] Ran `cargo clippy --all --features "empty"`
- [ ] Ran `cargo test --all --features "empty"`


1915: [FEATURE] Custom Logger Formatter r=azriel91,distransient a=nalshihabi

Implements #1889 

## Description

Add a custom log formatter option to the Amethyst logger so that instead of setting up their own logger to use their own formatting, a developer using Amethyst can just pass in their own formatter to the Amethyst logger.

## Additions

- `Logger::new_formatter`: a different constructor for Amethyst logger where a custom formatter can be passed as a parameter.
- `Logger::from_config_formatter`: a different function for the Logger for starting a new Logger with a config and a formatter.
- `Logger::new_with_config`: helper function that much of the functionality of `Logger::from_config` was moved into from `Logger::from_config` in order to allow for the functionality to be reused easily by `Logger::from_config_formatter`.

## Removals

None

## Modifications

- `Logger::from_config`: Changed to just call `Logger::from_config_formatter` with valid parameters for the helper function.

## PR Checklist

By placing an x in the boxes I certify that I have:

- [ ] Updated the content of the book if this PR would make the book outdated.
- [ ] Added a changelog entry if this will impact users, or modified more than 5 lines of Rust that wasn't a doc comment.
- [ ] Added unit tests for new code added in this PR.
- [x] Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.

If this modified or created any rs files:

- [x] Ran `cargo +stable fmt --all`
- [x] Ran `cargo clippy --all --features "empty"`
- [x] Ran `cargo test --all --features "empty"`


Co-authored-by: Azriel Hoh <azriel91@gmail.com>
Co-authored-by: Charles Saracco <crsaracco@gmail.com>
Co-authored-by: Noah AL-Shihabi <noahshihabi@gmail.com>
@mvlabat
Copy link
Member Author

mvlabat commented Oct 20, 2019

Works perfectly, thanks @nalshihabi for implementing!

@mvlabat mvlabat closed this as completed Oct 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
diff: easy Achievable by a single junior developer with a bit of guidance. pri: normal An issue that is causing a noticeable impact, but can be worked around team: engine type: feature A request for a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants