Saturday, July 9, 2016

Create ping request and logging output as needed

Here i have created a small Java program to make a ping request and log the output from the ping request.

Program does below
1. make "ping" request to list of ips/hosts
2. log total output to a log file =  log4j-application-20160709124113837.log
3. Host name and corresponding Average time = log4j-ping-20160709124113853.csv

I am creating log for each run. for that I am appending time as a suffix for log name.For that I have created a custom file appender "CustomFileAppender.java" and it is being used inside log4j.properties.

1. For ping , I have created  java class "PingStatistics .java"
2. Inside main method I have created a list of hosts/ips. Here I have included three names. google.com,yahoo.com and bing.com
3. for each item in the list, or each host name i create the ping command to execute. eg: let's say we are going to ping google.com, then command is "ping google.com".
"public static String createCommandForPing(String ip)" method is creating the command for each host.
4. we execute the command after creating command.
  the method "public static void executeCommnd(String command, String ip) ".
 Here parameter "ip" is used for logging purposes.
 If i explain execution...
   we need to have a runtime. So we create a runtime in Java

-------------------------------------------------------
          Runtime r = Runtime.getRuntime();
--------------------------------------------------------
 Then we execute the command using the runtime. command will execute in seperate process and we can get the return process as below.
----------------------------------------------------------
          Process p = r.exec(command);
----------------------------------------------------------

Then we can get the output of the process. we can't directly get a string. We need to get the InputStream and convert to Buffer and get line by line. First we create a "BufferedReader" from the input stream of the process.
----------------------------------------------------------
         BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
----------------------------------------------------------

Now e have the Buffer. Now we can read line by line of the output of the process. Or In other words , output of the execution of a ping command.

----------------------------------------------------------
String inputLine;
while ((inputLine = in.readLine()) != null) {
// System.out.println(inputLine);
log.info(inputLine);
pingResult += inputLine;
}
in.close();
----------------------------------------------------------

Remember to close the BufferedReader. "in.close(); "



Java code

======================================================================
package com.pingt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class PingStatistics {
static final Logger log = Logger.getLogger(PingStatistics.class);
final static Logger log_pingReport = Logger.getLogger("reportsLogger");

public static String createCommandForPing(String ip) {
String pingCmd = "ping " + ip;

return pingCmd;
}

/**
* ip added for logging purposes.
*
* @param command
* @param ip
*/
public static void executeCommnd(String command, String ip) {
StringBuilder pingDetails = new StringBuilder();
pingDetails.append(ip);
pingDetails.append(",");

String pingResult = "";
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(command);

BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
// System.out.println(inputLine);
log.info(inputLine);
pingResult += inputLine;
}
in.close();
System.out.println(pingResult);

String time = pingResult.substring(pingResult.indexOf("Average = "));
pingDetails.append(time);
log_pingReport.info(pingDetails);

} catch (IOException e) {
System.out.println(e);
}
}

public static String printPingDetailsHeader() {
StringBuilder header = new StringBuilder();
header.append("IP/Host Name");
header.append(",");
header.append("Average Time(ms)");

return header.toString();
}

public static void main(String[] args) {

List ipList = new ArrayList();
ipList.add("google.com");
ipList.add("yahoo.com");
ipList.add("bing.com");

log_pingReport.info(printPingDetailsHeader());
for (String ip : ipList) {
String command = createCommandForPing(ip);
executeCommnd(command,ip);
}

}
}

==================================================================

Below code for custom log Appender

==================================================================
package com.log;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.FileAppender;

public class CustomFileAppender extends FileAppender {

@Override
public void setFile(String fileName) {
if (fileName.indexOf("%timestamp") >= 0) {
Date d = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSS");
fileName = fileName.replaceAll("%timestamp", format.format(d));
}
super.setFile(fileName);
}
}

=================================================================

log4j.properties

==================================================================
# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=com.log.CustomFileAppender
log4j.appender.file.File=C:\\logs\\log4j-application-%timestamp.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n

log4j.category.reportsLogger=DEBUG, reportsLog
log4j.additivity.reportsLogger=false

log4j.appender.reportsLog=com.log.CustomFileAppender
log4j.appender.reportsLog.File=C:\\logs\\log4j-ping-%timestamp.csv
log4j.appender.reportsLog.layout=org.apache.log4j.PatternLayout
log4j.appender.reportsLog.layout.ConversionPattern=%m%n

===================================================================


Output for full log

===========  log4j-application-20160709124113837.log  =======================


Pinging google.com [74.125.200.102] with 32 bytes of data:
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46

Ping statistics for 74.125.200.102:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 49ms, Maximum = 49ms, Average = 49ms

Pinging yahoo.com [98.138.253.109] with 32 bytes of data:
Reply from 98.138.253.109: bytes=32 time=253ms TTL=46
Reply from 98.138.253.109: bytes=32 time=253ms TTL=46
Reply from 98.138.253.109: bytes=32 time=259ms TTL=46
Reply from 98.138.253.109: bytes=32 time=261ms TTL=44

Ping statistics for 98.138.253.109:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 253ms, Maximum = 261ms, Average = 256ms

Pinging bing.com [204.79.197.200] with 32 bytes of data:
Reply from 204.79.197.200: bytes=32 time=49ms TTL=118
Reply from 204.79.197.200: bytes=32 time=49ms TTL=118
Reply from 204.79.197.200: bytes=32 time=49ms TTL=118
Reply from 204.79.197.200: bytes=32 time=48ms TTL=118

Ping statistics for 204.79.197.200:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 48ms, Maximum = 49ms, Average = 48ms


==================================================================

== output for host name/average  log4j-ping-20160709124113853.csv ====================

IP/Host Name,Average Time(ms)
google.com,Average = 49ms
yahoo.com,Average = 256ms
bing.com,Average = 48ms


====================================================================


Create ping request and logging output as needed

Here i have created a small Java program to make a ping request and log the output from the ping request.

Program does below
1. make "ping" request to list of ips/hosts
2. log total output to a log file =  log4j-application-20160709124113837.log
3. Host name and corresponding Average time = log4j-ping-20160709124113853.csv

I am creating log for each run. for that I am appending time as a suffix for log name.For that I have created a custom file appender "CustomFileAppender.java" and it is being used inside log4j.properties.

1. For ping , I have created  java class "PingStatistics .java"
2. Inside main method I have created a list of hosts/ips. Here I have included three names. google.com,yahoo.com and bing.com
3. for each item in the list, or each host name i create the ping command to execute. eg: let's say we are going to ping google.com, then command is "ping google.com".
"public static String createCommandForPing(String ip)" method is creating the command for each host.
4. we execute the command after creating command.
  the method "public static void executeCommnd(String command, String ip) ".
 Here parameter "ip" is used for logging purposes.
 If i explain execution...
   we need to have a runtime. So we create a runtime in Java
          Runtime r = Runtime.getRuntime();
 Then we execute the command using the runtime. command will execute in seperate process and we can get the return process as below.
          Process p = r.exec(command);

Then we can get the output of the process. we can't directly get a string. We need to get the InputStream and convert to Buffer and get line by line. First we create a "BufferedReader" from the input stream of the process.
         BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));

Now e have the Buffer. Now we can read line by line of the output of the process. Or In other words , output of the execution of a ping command.

String inputLine;
while ((inputLine = in.readLine()) != null) {
// System.out.println(inputLine);
log.info(inputLine);
pingResult += inputLine;
}
in.close();

Remember to close the BufferedReader. "in.close(); "



Java code

======================================================================
package com.pingt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class PingStatistics {
static final Logger log = Logger.getLogger(PingStatistics.class);
final static Logger log_pingReport = Logger.getLogger("reportsLogger");

public static String createCommandForPing(String ip) {
String pingCmd = "ping " + ip;

return pingCmd;
}

/**
* ip added for logging purposes.
*
* @param command
* @param ip
*/
public static void executeCommnd(String command, String ip) {
StringBuilder pingDetails = new StringBuilder();
pingDetails.append(ip);
pingDetails.append(",");

String pingResult = "";
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(command);

BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
// System.out.println(inputLine);
log.info(inputLine);
pingResult += inputLine;
}
in.close();
System.out.println(pingResult);

String time = pingResult.substring(pingResult.indexOf("Average = "));
pingDetails.append(time);
log_pingReport.info(pingDetails);

} catch (IOException e) {
System.out.println(e);
}
}

public static String printPingDetailsHeader() {
StringBuilder header = new StringBuilder();
header.append("IP/Host Name");
header.append(",");
header.append("Average Time(ms)");

return header.toString();
}

public static void main(String[] args) {

List ipList = new ArrayList();
ipList.add("google.com");
ipList.add("yahoo.com");
ipList.add("bing.com");

log_pingReport.info(printPingDetailsHeader());
for (String ip : ipList) {
String command = createCommandForPing(ip);
executeCommnd(command,ip);
}

}
}

==================================================================

Below code for custom log Appender

==================================================================
package com.log;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.FileAppender;

public class CustomFileAppender extends FileAppender {

@Override
public void setFile(String fileName) {
if (fileName.indexOf("%timestamp") >= 0) {
Date d = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSS");
fileName = fileName.replaceAll("%timestamp", format.format(d));
}
super.setFile(fileName);
}
}

=================================================================

log4j.properties

==================================================================
# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=com.log.CustomFileAppender
log4j.appender.file.File=C:\\logs\\log4j-application-%timestamp.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n

log4j.category.reportsLogger=DEBUG, reportsLog
log4j.additivity.reportsLogger=false

log4j.appender.reportsLog=com.log.CustomFileAppender
log4j.appender.reportsLog.File=C:\\logs\\log4j-ping-%timestamp.csv
log4j.appender.reportsLog.layout=org.apache.log4j.PatternLayout
log4j.appender.reportsLog.layout.ConversionPattern=%m%n

===================================================================


Output for full log

===========  log4j-application-20160709124113837.log  =======================


Pinging google.com [74.125.200.102] with 32 bytes of data:
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46
Reply from 74.125.200.102: bytes=32 time=49ms TTL=46

Ping statistics for 74.125.200.102:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 49ms, Maximum = 49ms, Average = 49ms

Pinging yahoo.com [98.138.253.109] with 32 bytes of data:
Reply from 98.138.253.109: bytes=32 time=253ms TTL=46
Reply from 98.138.253.109: bytes=32 time=253ms TTL=46
Reply from 98.138.253.109: bytes=32 time=259ms TTL=46
Reply from 98.138.253.109: bytes=32 time=261ms TTL=44

Ping statistics for 98.138.253.109:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 253ms, Maximum = 261ms, Average = 256ms

Pinging bing.com [204.79.197.200] with 32 bytes of data:
Reply from 204.79.197.200: bytes=32 time=49ms TTL=118
Reply from 204.79.197.200: bytes=32 time=49ms TTL=118
Reply from 204.79.197.200: bytes=32 time=49ms TTL=118
Reply from 204.79.197.200: bytes=32 time=48ms TTL=118

Ping statistics for 204.79.197.200:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 48ms, Maximum = 49ms, Average = 48ms


==================================================================

== output for host name/average  log4j-ping-20160709124113853.csv ====================

IP/Host Name,Average Time(ms)
google.com,Average = 49ms
yahoo.com,Average = 256ms
bing.com,Average = 48ms


====================================================================


Friday, July 1, 2016

Creating a log for each run/Custom file appender and log different outputs details to different files

Here i explain how to create a log for each run. Basically by adding a custom appender.
next i need to log different details to different files. In simple log categories of details to different log files.

In my previous blog entry i have explained adding custom appender.
http://cgenit.blogspot.com/2016/07/writing-custom-file-appender-for-log4j_1.html

anyway I will explain again with steps

Step 1 - create java class for custom appender
Step 2 - add log4j entry for custom appender
Step 3 - add log4j entry for create another log for selected category
Step 4 -  used log4j category and write details to another log file


Step 1

======================================================
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.FileAppender;

public class CustomFileAppender extends FileAppender {

@Override
public void setFile(String fileName) {
if (fileName.indexOf("%timestamp") >= 0) {
Date d = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSS");
fileName = fileName.replaceAll("%timestamp", format.format(d));
}
super.setFile(fileName);
}
}

=======================================================


Step 2 and Step3  - log4j.properties

========================================================
# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n
####FullLog################
log4j.appender.file=com.research.log.CustomFileAppender
log4j.appender.file.File=D:\\Log\\FullLog-%timestamp.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n
######accountResult##############
log4j.category.accountResultLogger=DEBUG, accountResultLog
log4j.additivity.accountResultLogger=false
##
log4j.appender.accountResultLog=com.research.log.CustomFileAppender
log4j.appender.accountResultLog.File=D:\\Log\\accountResult-%timestamp.csv
log4j.appender.accountResultLog.layout=org.apache.log4j.PatternLayout
log4j.appender.accountResultLog.layout.ConversionPattern=%m%n
#####studentResultLog####
log4j.category.studentResultLogger=DEBUG, studentResultLog
log4j.additivity.studentResultLogger=false
##
log4j.appender.studentResultLog=com.research.log.CustomFileAppender
log4j.appender.studentResultLog.File=D:\\Log\\studentResult-%timestamp.csv
log4j.appender.studentResultLog.layout=org.apache.log4j.PatternLayout
log4j.appender.studentResultLog.layout.ConversionPattern=%m%n

==========================================================

Step 4

public class Logging {


final static Logger Log = Logger.getLogger(Logging.class);
final static Logger Log_accountResult = Logger.getLogger("accountResultLogger");
final static Logger Log_studentResult = Logger
.getLogger("studentResultLogger");

Log_accountResult.info("accountResult");
Log_studentResult.info("studentResult");

}

This will logging as per category in different files



Writing a custom File Appender for log4j

log4j is a powerful and very versatile tool. here is a code snippet to write a custom file Appender.
This way you can let the log4j to create a log file for each run.
This is the biggest advantage over custom appenders in log4j

Step 1

The way i desire, First we need to write a java class for making a custom appender.Let's call it "CustomFileAppender.java"

code will be as follows

================================================================
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.FileAppender;

public class CustomFileAppender extends FileAppender {

@Override
public void setFile(String fileName) {
if (fileName.indexOf("%timestamp") >= 0) {
Date d = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSS");
fileName = fileName.replaceAll("%timestamp", format.format(d));
}
super.setFile(fileName);
}
}

=====================================================================

her we add the date and time in format "yyyyMMddHHmmssSS" after the end of file name. In otherwords as a suffix.

eg: then your log file name would be like  "log-2016063014401283"

I believe that everybody understand the numbers

for ease of everybody, i will explain that part also

the format we use "yyyyMMddHHmmssSS" and  example is "2016063014401283".
let's take part by part from left to right.


Date formatter
Description
example
yyyy
year
2016
MM
MM
06
dd
date
30
HH
hours
14
mm
minutes
40
Ss (simple)
Seconds in minute
12
SS  (capital)
Milliseconds
83

for more information  refer


let's come back to logging.

Step 2

adding appender to log4j property file  "log4j.properties"

=============================================================
# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n
####FullLog################
log4j.appender.file=com.research.log.CustomFileAppender
log4j.appender.file.File=D:\\Log\\mergeOperation-%timestamp.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n

==========================================================


explanation

you can see that "log4j.rootLogger"  has "file" in line number 1

# Root logger option
log4j.rootLogger=DEBUG, stdout, file

next line describe, how we handle the standard output when running program. eg: when you run the program in console. you can print the output as needed modifying this.This is not what we are looking for.
Creating appender for the log file, what we log actually.That is explained in the below set.
# Redirect log messages to console

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n

here is how we add the custom appender.

log4j.appender.file=com.research.log.CustomFileAppender
log4j.appender.file.File=D:\\Log\\newLog-%timestamp.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n

we have created file option using "CustomFileAppender.java " class. Give the name with the package except ".java"

log4j.appender.file=com.research.log.CustomFileAppender

Then we create the name of the log file in the specific destination we need.We are creating log file inside folder name "Log" in drive "D". name of the log file is "newLog.log". But as we need to ad an appender , the time as a suffix to the log name with hyphen, we give new name as  "newLog-%timestamp.log"
It will be like this

log4j.appender.file.File=D:\\Log\\newLog-%timestamp.log

next two lines describe the pattern. first you give the patter class (log4j.appender.file.layou) for the patter and after that you can decide the pattern of the log with "log4j.appender.file.layout.ConversionPattern" property.

log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n







Writing a custom File Appender for log4j

log4j is a powerful and very versatile tool. here is a code snippet to write a custom file Appender.

Step 1

The way i desire, First we need to write a java class for making a custom appender.Let's call it "CustomFileAppender.java"

code will be as follows

================================================================
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.FileAppender;

public class CustomFileAppender extends FileAppender {

@Override
public void setFile(String fileName) {
if (fileName.indexOf("%timestamp") >= 0) {
Date d = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSS");
fileName = fileName.replaceAll("%timestamp", format.format(d));
}
super.setFile(fileName);
}
}

=====================================================================

her we add the date and time in format "yyyyMMddHHmmssSS" after the end of file name. In otherwords as a suffix.

eg: then your log file name would be like  "log-2016063014401283"

I believe that everybody understand the numbers

for ease of everybody, i will explain that part also

the format we use "yyyyMMddHHmmssSS" and  example is "2016063014401283".
let's take part by part from left to right.


Date formatter
Description
example
yyyy
year
2016
MM
MM
06
dd
date
30
HH
hours
14
mm
minutes
40
Ss (simple)
Seconds in minute
12
SS  (capital)
Milliseconds
83

for more information  refer


let's come back to logging.

Step 2

adding appender to log4j property file  "log4j.properties"

=============================================================
# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n
####FullLog################
log4j.appender.file=com.research.log.CustomFileAppender
log4j.appender.file.File=D:\\Log\\mergeOperation-%timestamp.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n

==========================================================


explanation

you can see that "log4j.rootLogger"  has "file" in line number 1

# Root logger option
log4j.rootLogger=DEBUG, stdout, file

next line describe, how we handle the standard output when running program. eg: when you run the program in console. you can print the output as needed modifying this.This is not what we are looking for.
Creating appender for the log file, what we log actually.That is explained in the below set.
# Redirect log messages to console

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%m%n

here is how we add the custom appender.

log4j.appender.file=com.research.log.CustomFileAppender
log4j.appender.file.File=D:\\Log\\newLog-%timestamp.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n

we have created file option using "CustomFileAppender.java " class. Give the name with the package except ".java"

log4j.appender.file=com.research.log.CustomFileAppender

Then we create the name of the log file in the specific destination we need.We are creating log file inside folder name "Log" in drive "D". name of the log file is "newLog.log". But as we need to ad an appender , the time as a suffix to the log name with hyphen, we give new name as  "newLog-%timestamp.log"
It will be like this

log4j.appender.file.File=D:\\Log\\newLog-%timestamp.log

next two lines describe the pattern. first you give the patter class (log4j.appender.file.layou) for the patter and after that you can decide the pattern of the log with "log4j.appender.file.layout.ConversionPattern" property.

log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%m%n