The OOTB ConnectorServer.exe.Config file contains the following <listeners> tag:
<listeners>
<remove name="Default" />
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="c:\connectorserver.log"
traceOutputOptions="DateTime">
<filter type="System.Diagnostics.EventTypeFilter"
initializeData="Information"/>
</add>
</listeners>
This produces a single file in the c: drive. This file can, and does, grow with no way to roll or otherwise start the file over, except to stop the connector server, delete the file, and then restart the connector server.
Instead of using the TextWriterTraceListener, another option can be chosen.
Here is the other option:
<listeners>
<remove name="Default" />
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,Microsoft.VisualBasic,Version=8.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
initializeData="FileLogWriter"
traceOutputOptions="DateTime"
BaseFileName="ConnectorServer"
Location="Custom"
MaxFileSize="600000000"
CustomLocation="D:\Identity Connectors\Logs\"
LogFileCreationSchedule="Daily">
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Information" />
</add>
</listeners>
You will need to find a way to clean up the log files with an external process. The FileLogTraceListener does not have any options for deleting logs. See these links:
FileLogTraceListener
TraceOutputOptions Values
Thanks for viewing my blog on Identity Management and Engineering (mostly IDM). Please follow and check out the advertisers.
Search This Blog
Wednesday, February 18, 2015
Getting java.util.logging to work with JUnit
In my development I normally create the JUnit test cases, but had trouble getting the java.util.logging statement to activate in the code I was testing. I discovered a couple articles on the web and pieced them together for a solution.
As a reference, here is how I normally implement logging, with my OIM Flat File Connector XMLParser as the class:
import java.util.logging.*;
public class FlatFileXMLParser implements FlatFileParser {
private static final Logger logger =
Logger.getLogger(FlatFileXMLParser.class.getName());
public void parse(File flatFile, FlatFileRecordHandler recordHandler,
ParserConfig config) throws Exception {
String methodName="parse";
logger.logp(Level.FINE, getClass().getName(), methodName,
"FF-XMLP-001 entering");
Some explanation:
1) I use java.util.logging and never use log4j.
2) I use logp - never anything else. One statement=commonality
3) I define String methodName to provide the method name in every module.
4) I add tags so that I can grep on the tags. Each statement gets a tag.
5) Increment the numbers in the method and skip to next 100 on next method.
6) Debug statements as Level.FINE, use good judgement.
When I attempt to test these code modules I found that the logging was not being generated. I found a great writeup and took most of this from it. What I did was put the following into the JUnit class - not in the functional class:
public class AppTest extends TestCase {
static {
Logger rootLogger = Logger.getLogger("");
System.setProperty("java.util.logging.SimpleFormatter.format",
"[%1$tF %1$tr] [%2$s] %4$s: %5$s %n");
for(Handler handler : rootLogger.getHandlers()) {
handler.setLevel(Level.FINEST);
handler.setFormatter(new SimpleFormatter());
}
rootLogger.setLevel(Level.FINEST);
}
After this is the constructor and the test methods. The logger will record the details to the output screen and you can track your code.
Good luck testing !!
As a reference, here is how I normally implement logging, with my OIM Flat File Connector XMLParser as the class:
import java.util.logging.*;
public class FlatFileXMLParser implements FlatFileParser {
private static final Logger logger =
Logger.getLogger(FlatFileXMLParser.class.getName());
public void parse(File flatFile, FlatFileRecordHandler recordHandler,
ParserConfig config) throws Exception {
String methodName="parse";
logger.logp(Level.FINE, getClass().getName(), methodName,
"FF-XMLP-001 entering");
Some explanation:
1) I use java.util.logging and never use log4j.
2) I use logp - never anything else. One statement=commonality
3) I define String methodName to provide the method name in every module.
4) I add tags so that I can grep on the tags. Each statement gets a tag.
5) Increment the numbers in the method and skip to next 100 on next method.
6) Debug statements as Level.FINE, use good judgement.
When I attempt to test these code modules I found that the logging was not being generated. I found a great writeup and took most of this from it. What I did was put the following into the JUnit class - not in the functional class:
public class AppTest extends TestCase {
static {
Logger rootLogger = Logger.getLogger("");
System.setProperty("java.util.logging.SimpleFormatter.format",
"[%1$tF %1$tr] [%2$s] %4$s: %5$s %n");
for(Handler handler : rootLogger.getHandlers()) {
handler.setLevel(Level.FINEST);
handler.setFormatter(new SimpleFormatter());
}
rootLogger.setLevel(Level.FINEST);
}
After this is the constructor and the test methods. The logger will record the details to the output screen and you can track your code.
Good luck testing !!
Subscribe to:
Posts (Atom)