Skip to content

logging functions handle unicode poorly #2154

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jesse99 opened this issue Apr 7, 2012 · 3 comments
Closed

logging functions handle unicode poorly #2154

jesse99 opened this issue Apr 7, 2012 · 3 comments
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows A-Unicode Area: Unicode C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@jesse99
Copy link
Contributor

jesse99 commented Apr 7, 2012

If I log a string with unicode I would like to see the unicode not some wacky utf-8 multi-byte escape sequence. Here is a test case:

// Run with export RUST_LOG=test && ./test
import io;

fn is_print(ch: char) -> bool
{
ret ch >= '_' && ch <= '~';
}

fn munge_chars(chars: [char]) -> str
{
let bullet = '\u2022';

let mut value = "";
str::reserve(value, vec::len(chars));
vec::iter(chars) {|ch| str::push_char(value, if is_print(ch) {ch} else {bullet});}
ret value;

}

fn main()
{
let s = munge_chars(['h', 'e', 'l', 'l', 'o', '\u0003']);

// With the terminal on Mac OSX this prints the following two lines:
// hello<bullet symbol>
// rust: "hello\xffffffe2\xffffff80\xffffffa2"
io::println(s);
#info("%s", s);

}

@jesse99
Copy link
Contributor Author

jesse99 commented Apr 7, 2012

Gah, here is the code again without markdown hosing it:

// Run with `export RUST_LOG=hello && ./bin/hello`
import io;

fn is_print(ch: char) -> bool
{
    ret ch >= '_' && ch <= '~';
}

fn munge_chars(chars: [char]) -> str
{
    let bullet = '\u2022';

    let mut value = "";
    str::reserve(value, vec::len(chars));
    vec::iter(chars) {|ch| str::push_char(value, if is_print(ch) {ch} else {bullet});}
    ret value;
}

fn main() 
{
    let s = munge_chars(['h', 'e', 'l', 'l', 'o', '\u0003']);

    // With the terminal on Mac OSX this prints the following two lines:
    // hello<bullet>
    // rust: "hello\xffffffe2\xffffff80\xffffffa2"
    io::println(s);
    #info("%s", s);
}

@ghost ghost assigned brson Apr 12, 2012
@bstrie
Copy link
Contributor

bstrie commented Jun 25, 2013

Here's a simpler test case:

fn main() {
    error!("über");
}

We expect it to output ~"\"über\"" (god, that is so hideous) but instead we get the even-more-monstrous ~"\"\\xfcber\"".

@alexcrichton
Copy link
Member

This is fixed with error2! which is soon-to-replace the error macro, so I'm going to close this as fixed for now.

Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 29, 2024
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows A-Unicode Area: Unicode C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants