logger icon indicating copy to clipboard operation
logger copied to clipboard

break 4000 words maybe error for Chinese character

Open pscj opened this issue 9 years ago • 4 comments

byte[] bytes = message.getBytes();
int length = bytes.length;
...
for (int i = 0; i < length; i += CHUNK_SIZE) {
  int count = Math.min(length - i, CHUNK_SIZE);

one chinese character may be 2 or 3 bytes in UTF-8. if the 4000th character is chinese char with 2 bytes, the char will be split. so the log cann't show the char correctly.

pscj avatar Jul 27 '16 09:07 pscj

See this issue by accident…… if you're still in trouble of this, maybe another log library Android-PLog may help you.:smile:

Muyangmin avatar Sep 08 '16 09:09 Muyangmin

@pscj Thanks for this issue, I'll definitely take a look for this. A good case! I'll add this one in backlog

orhanobut avatar Oct 25 '16 12:10 orhanobut

@pscj I'll add this issue with the upcoming version. It'll be interesting.

orhanobut avatar May 28 '17 11:05 orhanobut

i have the same confusion,and i resolve it like this

    private void method3(String message){
        String tmp = "";
        for(int i = 0; i < message.length(); i++){
            char c = message.charAt(i);
            String add = tmp + c;
            if(add.getBytes().length <= CHUNK_SIZE){
                tmp += c;
            } else {
                Log.i("tag_3", i + " --> " + tmp + " --> " + tmp.getBytes().length);
                tmp = c + "";
            }
        }
        if(tmp.length() != 0){
            Log.i("tag_3", tmp + " --> " + tmp.getBytes().length);
        }
    }

maybe it's inefficient,but who care this when print the log.

meijieman avatar Aug 30 '17 16:08 meijieman