Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[bug]自带的日志Logger的死循环bug #16

Closed
diracccc opened this issue May 1, 2019 · 3 comments
Closed

[bug]自带的日志Logger的死循环bug #16

diracccc opened this issue May 1, 2019 · 3 comments

Comments

@diracccc
Copy link
Contributor

diracccc commented May 1, 2019

在Logger的这个方法,如果在写入日志文件发生异常,代码就会走到后面一段,即从queue里poll出日志然后System.out.print输出,然后Tars的日志系统把System的out/err都冲定向到这个LoggingOutputstream,而这个流的flush方法,就是调用Logger的info方法,最终就是offer一个日志到这个queue里,然后发生死循环,一边offer一边poll。

private void writeAllToLocal(String file) {
        boolean succ = false;
        if (file != null) {
            BufferedWriter bw = null;
            try {
                if (!logQueue.isEmpty()) {
                    bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file + "." + Utils.getDateSimpleInfo(System.currentTimeMillis()), true), "UTF-8"));
                    LogItem item = null;
                    while ((item = logQueue.poll()) != null) {
                        bw.write(item.toString());
                    }
                }
                succ = true;
            } catch (IOException ex) {

            } finally {
                if (bw != null) {
                    try {
                        bw.close();
                    } catch (IOException e) {
                    }
                }
            }
        }
        if (!succ) {
            LogItem item = null;
            while ((item = logQueue.poll()) != null && !STDOUT_LOG.equals(name)) {
                System.out.print("\t" + item.toString());
            }
        }
    }
@c-zhengjianbin
Copy link

使用Idea 查看项目依赖图,删除循环依赖问题

@diracccc
Copy link
Contributor Author

使用Idea 查看项目依赖图,删除循环依赖问题

?没懂。

@TimmyYu
Copy link
Contributor

TimmyYu commented Jan 9, 2020

这里最终输出的是 System.out.print,在STDOUT_LOG.equals(name) 判断了,所以stderr输出后。到这里就不会再输出了。只会输出一次

@TimmyYu TimmyYu closed this as completed Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants