如果存储在应用程序外,如何检索log4j2.xml

时间:2017-02-09 22:37:43

标签: java maven logging log4j log4j2

我正在做一个maven应用程序。如果我将log4j2.xml配置文件放在src/resources文件夹中,它可以正常工作。

但是,我需要将它存储在应用程序之外。如果log4j2.xml文件存储在我的桌面上,如何调用src/resource文件的位置?我应该在 <?php if(isset($_POST['submit'])) { //database connection include_once("include-php/db-conx-local.php"); //gather variables from form and scrub $name = preg_replace('#[^a-z0-9]#i', 3'', $_POST['name']); $email = mysqli_real_escape_string($db_conx, $_POST['email']); $subject = preg_replace('#[^a-z0-9]#i', '', $_POST['subject']); // Function to get the client IP address $ip = getenv('HTTP_CLIENT_IP')?: getenv('HTTP_X_FORWARDED_FOR')?: getenv('HTTP_X_FORWARDED')?: getenv('HTTP_FORWARDED_FOR')?: getenv('HTTP_FORWARDED')?: getenv('REMOTE_ADDR'); // FORM DATA ERROR HANDLING if($name == "" || $email == "" || $subject == ""){ echo "Please fill out the entire form."; exit(); } else { $sql = "INSERT INTO emailContactForm (name, email, subject, ip, postDate) VALUES ('$name', '$email', '$subject', '$ip', now())"; mysqli_query($db_conx, $sql); } exit(); } ?> <form action="contact.php" method="post" id="contact-form"> <div class="input-prepend"> <span class="add-on"><i class="icon-user"></i></span> <input class="span4" id="name" name="name" size="16" type="text" placeholder="Name"> </div> <div class="input-prepend"> <span class="add-on"><i class="icon-envelope"></i></span> <input class="span4" id="email" name="email" size="16" type="text" placeholder="Email Address"> </div> <textarea class="span6" id="subject" name="subject"></textarea> <div class="row"> <div class="span2"> <input type="submit" id="submit" class="btn btn-inverse" value="Send Message"> </div> </div> </form> 文件夹中创建一个文件来读取我的日志文件位置,我该怎么做?

1 个答案:

答案 0 :(得分:2)

Log4j2配置文件不需要在类路径中。

您可以使用系统属性-Dlog4j.configurationFile=path/to/log4j2.xml指定相对路径或完整路径。

另见Log4j2 FAQ page