-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert removing
log
and changes to on_error
We still want the `log` feature to exist until all buildpacks have transitioned over to `build_output`, since: 1. It will ease the transition for repositories where there are multiple buildpacks, since each buildpack can be migrated to `build_output` individually, rather than needing to do all of them at once. 2. It means any buildpacks that cannot switch to `build_output` right away, can still stay up to date with other libcnb changes. The change to `on_error` has also been reverted, since: 1. It's a change that's standalone from introducing the `build_output` module (ie: lets first introduce a new thing, then afterwards handle migrating things to use it) 2. It's otherwise yet another thing we need to review in this already very-long lived PR, and it would be best to avoid further delays. (I can see at least one issue with the change that would need fixing, and I haven't even reviewed it fully yet.)
- Loading branch information
Showing
5 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::io::Write; | ||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; | ||
|
||
/// # Panics | ||
/// | ||
/// Will panic if there was a problem setting the color settings, or all bytes could | ||
/// not be written due to either I/O errors or EOF being reached. | ||
// TODO: Replace `.unwrap()` usages with `.expect()` to give a clearer error message: | ||
// https://github.com/heroku/libcnb.rs/issues/712 | ||
#[allow(clippy::unwrap_used)] | ||
pub fn log_error(header: impl AsRef<str>, body: impl AsRef<str>) { | ||
let mut stream = StandardStream::stderr(ColorChoice::Always); | ||
stream | ||
.set_color(ColorSpec::new().set_fg(Some(Color::Red)).set_bold(true)) | ||
.unwrap(); | ||
writeln!(&mut stream, "\n[Error: {}]", header.as_ref()).unwrap(); | ||
stream.reset().unwrap(); | ||
|
||
stream | ||
.set_color(ColorSpec::new().set_fg(Some(Color::Red))) | ||
.unwrap(); | ||
writeln!(&mut stream, "{}", body.as_ref()).unwrap(); | ||
stream.flush().unwrap(); | ||
} | ||
|
||
/// # Panics | ||
/// | ||
/// Will panic if there was a problem setting the color settings, or all bytes could | ||
/// not be written due to either I/O errors or EOF being reached. | ||
// TODO: Replace `.unwrap()` usages with `.expect()` to give a clearer error message: | ||
// https://github.com/heroku/libcnb.rs/issues/712 | ||
#[allow(clippy::unwrap_used)] | ||
pub fn log_warning(header: impl AsRef<str>, body: impl AsRef<str>) { | ||
let mut stream = StandardStream::stderr(ColorChoice::Always); | ||
stream | ||
.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)).set_bold(true)) | ||
.unwrap(); | ||
writeln!(&mut stream, "\n[Warning: {}]", header.as_ref()).unwrap(); | ||
stream.reset().unwrap(); | ||
|
||
stream | ||
.set_color(ColorSpec::new().set_fg(Some(Color::Yellow))) | ||
.unwrap(); | ||
writeln!(&mut stream, "{}", body.as_ref()).unwrap(); | ||
stream.flush().unwrap(); | ||
} | ||
|
||
/// # Panics | ||
/// | ||
/// Will panic if there was a problem setting the color settings, or all bytes could | ||
/// not be written due to either I/O errors or EOF being reached. | ||
// TODO: Replace `.unwrap()` usages with `.expect()` to give a clearer error message: | ||
// https://github.com/heroku/libcnb.rs/issues/712 | ||
#[allow(clippy::unwrap_used)] | ||
pub fn log_header(title: impl AsRef<str>) { | ||
let mut stream = StandardStream::stdout(ColorChoice::Always); | ||
stream | ||
.set_color(ColorSpec::new().set_fg(Some(Color::Magenta)).set_bold(true)) | ||
.unwrap(); | ||
writeln!(&mut stream, "\n[{}]", title.as_ref()).unwrap(); | ||
stream.reset().unwrap(); | ||
stream.flush().unwrap(); | ||
} | ||
|
||
/// # Panics | ||
/// | ||
/// Will panic if all bytes could not be written due to I/O errors or EOF being reached. | ||
// TODO: Replace `.unwrap()` usages with `.expect()` to give a clearer error message: | ||
// https://github.com/heroku/libcnb.rs/issues/712 | ||
#[allow(clippy::unwrap_used)] | ||
pub fn log_info(message: impl AsRef<str>) { | ||
println!("{}", message.as_ref()); | ||
std::io::stdout().flush().unwrap(); | ||
} |