Linux application deployment console output

Many java applications need to be deployed on linux servers. If our java program uses system.out.println() to print logs on the linux server, the following steps are required.

1. The java program needs to configure the log4j log file and define the console output

log4j.rootLogger=INFO, console, rolling

 

log4j.appender.console=org.apache.log4j.ConsoleAppender

log4j.appender.console.layout=org.apache.log4j.PatternLayout

log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [T=%t] [%c %M at 

%L]-[%p] %m%n

 

log4j.appender.rolling=org.apache.log4j.RollingFileAppender

log4j.appender.rolling.layout=org.apache.log4j.PatternLayout

log4j.appender.rolling.MaxFileSize=100MB

log4j.appender.rolling.MaxBackupIndex=10

log4j.appender.rolling.File=./log/FtpProxyMonitor.log

log4j.appender.rolling.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [T=%t] [%c %M at 

%L]-[%p] %m%n

Among them, org.apache.log4j.ConsoleAppender is to configure console output. If log4j is not configured, it will report an error not found

 

2. When the application is deployed, there needs to be a startup command line 

  2.1 Not applicable to nohup startup

   ${JAVA_HOME}/bin/java  -Xms64m -Xmx64m -Duser.timezone=GMT+8 -cp ${JARS} ${APP_NAME} 10.255.242.30 21 admin Cmcba PLOG  

  If so the system log will be printed at the top of the screen when the program starts. But we usually direct the console output to the run.out file

   ${JAVA_HOME}/bin/java  -Xms64m -Xmx64m -Duser.timezone=GMT+8 -cp ${JARS} ${APP_NAME} 10.255.242.30 21 admin Cmcba PLOG  >run.out

  2.2 Start with nohup background operation

   nohup ${JAVA_HOME}/bin/java  -Xms64m -Xmx64m -Duser.timezone=GMT+8 -cp ${JARS} ${APP_NAME} 10.255.242.30 21 admin Cmcba PLOG  &

   In this way, the console output will be output to the nohup.out file by default.

  If the definition points to the run.out file, the console output will be output to the run.out file, not to the nohup.out file

   nohup ${JAVA_HOME}/bin/java  -Xms64m -Xmx64m -Duser.timezone=GMT+8 -cp ${JARS} ${APP_NAME} 10.255.242.30 21 admin Cmcba PLOG  >run.out &

 

3. If we don't want to print console output, we can turn off console output and error output

    nohup ${JAVA_HOME}/bin/java  -Xms64m -Xmx64m -Duser.timezone=GMT+8 -cp ${JARS} ${APP_NAME} 10.255.242.30 21 admin Cmcba PLOG  >/dev/null 2>&1 &

   This way the system output will no longer be printed.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326572678&siteId=291194637