java -D"file.encoding=utf-8" -Dargs_path=/data/soft/jenkins_node_release/workspace/yougou_front/args.properties

-jar com.test.report.jmeterTestReport_new.jar

-D 表示要传入的参数,多个参数用多个-Dxxx传入

调用方式见dos窗口

java 在dos窗口调用jar包调试-LMLPHP

结果见日志

java 在dos窗口调用jar包调试-LMLPHP

下面为源码部分

package com.belle.log;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;

import java.io.File;
import java.io.IOException;

/**
 * @param "logObject"=传入的日志内容格式,"fileType"=是否覆盖文件(true or false),"jobName"=工程名称
 * @author qgl
 * @version 2019-02-13 10:08:18
 */
public class Log4jTest {

    //声明当前类Log4jTest.class为日志类

    public static Log log = LogFactory.getLog(Log4jTest.class);

    // 定义logger对象,后面的参数和properties文件中是有对应关系的,如果没有就会报错

    private static final Logger logs = Logger.getLogger("secondLogger");
    private static final Logger logs1 = Logger.getLogger("secondLogger1");
    // 获取日志信息

    public String getLogInfo(Object logObject, Boolean fileType, String jobName) throws IOException {
        File file = new File("data/applogs/alarm.log");
        if (!file.exists()) {
            file.getParentFile().mkdir();
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        if (fileType.equals(true)) {
            Appender appender = new FileAppender(new SimpleLayout(), "data/applogs/alarm.log");
            logs.addAppender(appender);
            logs.info(logObject);
            System.out.println("log不被覆盖..................");
        } else {
            if (file.delete()) {
                System.out.println("-------------删除文件成功!-------------");
            }
            Appender appender = new FileAppender(new SimpleLayout(), "data/applogs/alarm.log");
            logs1.addAppender(appender);
            logs1.info(logObject);
        }
        return "SUCCESS";
    }


    public static void main(String[] args) throws IOException {
        Log4jTest log4jTest = new Log4jTest();
        log4jTest.getLogInfo(System.getProperty("logObject"),
                Boolean.valueOf(System.getProperty("fileType")), System.getProperty("jobName"));
    }

}
02-14 14:23