简体   繁体   English

程序登录到控制台时会发生什么?

[英]What happens when a program logs to the console?

I have a java server application running that uses Logback as its primary logging library. 我运行的Java服务器应用程序使用Logback作为其主要日志记录库。 Recently I asked a developer to remove the extra console logging they had added for a non-development environment and when they asked me why realized I didn't have solid reasoning for it. 最近,我要求开发人员删除他们为非开发环境添加的额外控制台日志,并且当他们问我为什么意识到我对此没有充分的理由时。

The extra logging I believe would cause more I/O operations but does it also add more memory usage? 我相信额外的日志记录会导致更多的I / O操作,但是还会增加内存使用量吗? How large is the buffer that it's writing to in stdout and when is that cleared? 它在stdout中写入的缓冲区有多大?何时清除?

Our standard logging is to a file which we can view or also have it piped into monitoring tools. 我们的标准日志记录到一个文件,我们可以查看该文件,也可以将其通过管道传输到监视工具中。 The application is deployed via an automated process and is headless so generally no one is on the VM looking at things. 该应用程序是通过自动化流程进行部署的,并且没有头,因此通常没有人在VM上看东西。

Example logging appenders ( Dropwizard configurations ) 日志附加程序示例( Dropwizard配置

logging:
  level: INFO
  appenders:
    - type: file
      currentLogFilename: /var/log/myapplication.log
      archive: true
      archivedFileCount: 5
    - type: console
      target: stdout

Essentially, is there a detriment to logging to the console when not using it and what does that take the form of? 本质上,在不使用控制台时,是否有损于登录控制台,它的形式是什么?

Unless you are logging millions of records, logging has no noticeable impact on performance. 除非您要记录数百万条记录,否则记录不会对性能产生明显影响。

Logging to the console is more ephemeral than logging to a file--the log messages are not saved anywhere. 登录到控制台比登录到文件更短暂-日志消息不会保存在任何地方。 This makes it impossible to track down errors and troubleshoot problems, especially in production. 这样就不可能跟踪错误并排除故障,特别是在生产中。

Logging to STDOUT can be useful if you run your application inside a container like Docker. 如果在Docker之类的容器中运行应用程序,则登录到STDOUT可能会很有用。 Docker can fetch anything written to STDOUT and STDERR in any container it runs using docker logs or can redirect to a different server. Docker可以在使用Docker docker logs运行的任何容器中提取写入STDOUT和STDERR的任何内容,或者可以重定向到其他服务器。 If the application would write to a logfile local to the container it runs it, it would be much more difficult to access this file from outside the container. 如果应用程序将写入容器本地运行的日志文件,则从容器外部访问该文件将更加困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java程序启动时会发生什么? - What happens when java program starts? 当程序未在命令窗口中打开时,println()语句会发生什么? - What happens with println() statements when the program is not open in command window? 当单个程序有多个 ThreadPoolExecutor 时会发生什么? - What happens when a single program has multiple `ThreadPoolExecutor`s? 当您关闭电源时,Java 程序会发生什么? - What happens to a Java program when you turn the power off? 套接字:当收到read()消息时未阻止程序时会发生什么情况 - Sockets: what happens when the program is not blocked on read() message is received 线程“main”中的异常 java.util.InputMismatchException .. 当我尝试运行程序时会发生这种情况 - Exception in thread “main” java.util.InputMismatchException.. that's what happens when i try to run the program 当GC不(必须)运行并且程序完成其执行时会发生什么? - What happens when GC doesn't (have to) run and program finishes its execution? 操作系统(linux)如何杀死Java程序? 当我硬杀死一个Java进程时,jvm会怎样? - how operating system(linux) kills java program ? What happens to the jvm when I hard kill a java process? 变量未初始化时会发生什么? - What happens when a variable is uninitialized? 引发错误时会发生什么? - What happens when Error is thrown?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM