bonjour à tous;
voila mon logger marche bien lorsque que je l'utilise d'un main de test, mais des que je l insere dans mon appli (sous eclipse) ben ca marche plus ....
le code du loggger
[code]package de.conti.ptc.tdm.utils.NetworkTest;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
public class NetworkTestLogger {
private static NetworkTestLogger instance = null;
private String configFilePath = "../../ip3.ini";
protected static long milliseconds_since_start;
private static Logger logger = null;
private Properties properties;
public NetworkTestLogger() {
logger=Logger.getLogger("NetworkTestLogger");
}
//find pathfile of file '.dat' in configfile
protected String getProperty(String propertyName) throws IOException{
String propertyValue ;
FileInputStream in;
if (properties == null){
properties = new Properties();
in = new FileInputStream(configFilePath);
properties.load(in);
in.close();
}
propertyValue = properties.getProperty(propertyName);
if (propertyValue == null){
propertyValue = "";
}
return (propertyValue);
}
public void sendLogger(String application,String action) throws IOException {
String pattern;
DailyRollingFileAppender appender;
PatternLayout layout;
BasicConfigurator.configure();
pattern = "Tlse;"; //database
pattern += application + ";";//program source
pattern += action + ";";//done action
pattern += System.getProperty("user.name") + ";";//user
pattern += InetAddress.getLocalHost().getHostName() + ";"; //n° computer
pattern += new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date())+ ";"; //date
pattern += (System.currentTimeMillis() - milliseconds_since_start);// time in ms
layout = new PatternLayout(pattern + "\n");
appender = new DailyRollingFileAppender(layout, getProperty("logFolder") + "LogNetworkTest.dat", "'.'yyyy-ww");
logger.addAppender(appender);
logger.debug(appender);
}
public static NetworkTestLogger getInstance() throws IOException {
if (instance == null) {
instance = new NetworkTestLogger();
}
milliseconds_since_start = System.currentTimeMillis();
return instance;
}
}
[/code]
celui de la classe de test
[code]package de.conti.ptc.tdm.utils.NetworkTest;
public class Test {
public static void main(String[] args) {
try {
NetworkTestLogger.getInstance();
Thread.sleep(1000);
NetworkTestLogger.getInstance().sendLogger("source","action n° ");
}
catch (Exception e) {
}
}
}
[/code]
celui de la partie du programme ou ca marche pas
[code]package de.conti.ptc.tdm.infopool3;
import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.ui.part.ViewPart;
import de.conti.ptc.tdm.utils.NetworkTest.NetworkTestLogger;
import de.conti.ptc.tdm.utils.calendarForIp3.ColorCache;
import de.conti.ptc.tdm.utils.persistence.ToplinkSession;
import de.conti.ptc.tdm.utils.plugin.OpenViewAction;
/**
* Empty view which allows to display something when no plugins are opened.
*/
public class EmptyView extends ViewPart {
//ID of the view
public static final String ID = OpenViewAction.getEmptyViewId();
//Text displayed inside the view
private static Label infoLabel;
private static Composite container;
private static ProgressBar progressBar;
private static boolean firstLoad = true;
private static float connectionTime;
private static NetworkTestLogger networktestlogger;
/**
* Defines the content of the view
*/
public void createPartControl(Composite parent) {
container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout());
container.setBackground(ColorCache.getWhite());
if (firstLoad){
/*try {
Integer.parseInt("Hello world");
} catch (Exception e) {
//marche pas !!!
IP3Exception.getInstance(e);
}*/
for (int i=0;i<20;i++){
new Label(container,SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.LEFT, true, false, 1, 1));;
}
infoLabel = new Label(container, SWT.NONE);
infoLabel.setFont(new Font(parent.getDisplay(),"Arial",10,SWT.BOLD));
infoLabel.setBackground(ColorCache.getWhite());
infoLabel.setText("Connecting to the Database...");
infoLabel.setLayoutData(new GridData(SWT.CENTER, SWT.LEFT, true, false, 1, 1));
progressBar = new ProgressBar(container,SWT.INDETERMINATE|SWT.BORDER);
progressBar.setLayoutData(new GridData(SWT.CENTER, SWT.LEFT, true, true, 1, 1));
progressBar.setMinimum(0);
progressBar.setMaximum(100);
progressBar.setSelection(30);
progressBar.setBounds(0,0,250,20);
firstLoad = false;
}
}
/**
* Actions to do when the focus is on the view
*/
public void setFocus() {
}
public static void connection(){
final Thread threadEndConnection = new Thread() {
public void run() {
connectionTime = (float) ((System.currentTimeMillis() - ApplicationWorkbenchWindowAdvisor.startTime) / 1000.0);
progressBar.dispose();
infoLabel.setText(" Connected in " + connectionTime + " s");
try {
NetworkTestLogger.getInstance().sendLogger("IP3","TopLinkLoad");
} catch (IOException e) {
}
}
};
Thread threadStartConnection = new Thread() {
public void run() {
try {
NetworkTestLogger.getInstance();
} catch (IOException e1) {
}
ToplinkSession.getInstance();
try{
Display.getDefault().syncExec(threadEndConnection);
}
catch(Exception e){
//if the users opens a tab without waiting for the end of the connection
//do nothing
}
}
};
threadStartConnection.start();
}
}
[/code]
dans le cas ou ca marche pas je passe bien dans toutes mes fonctions appelées mais les 2 commandes :
[code]logger.addAppender(appender);
logger.debug(appender); [/code]
ne se deroule pas?????
et la je sais pas pourquoi ..
help me please