hamster007
Messages postés2Date d'inscriptionjeudi 24 juillet 2008StatutMembreDernière intervention25 août 2008
-
30 juil. 2008 à 09:16
cs_AlexN
Messages postés694Date d'inscriptionlundi 5 décembre 2005StatutMembreDernière intervention 8 janvier 2014
-
30 juil. 2008 à 10:54
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
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;
}
}
celui de la classe de test
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) {
}
}
}
celui de la partie du programme ou ca marche pas
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();
}
}
dans le cas ou ca marche pas je passe bien dans toutes mes fonctions appelées mais les 2 commandes :
cs_AlexN
Messages postés694Date d'inscriptionlundi 5 décembre 2005StatutMembreDernière intervention 8 janvier 201419 30 juil. 2008 à 10:54
Salut,
Le logger n'est pas determiné par un nom court de classe mais par le nom complet de la classe à logger.
Dans ton exemple, ta classe "NetworkTest" est située dans le package "de.conti.ptc.tdm.utils.NetworkTest"
- Il semble que tu ai voulu créer un singleton pour ton logger, mais le constructeur n'est pas privé. Ce n'est pas un singleton, n'importe qui peut construire un NetworkTestLogger sans passer par getInstance().
- Les loggers sont déjà uniques (un logger par classe), logger.getLogger(class) permet de retrouver ce logger. Je ne pense pas que ce soit utile de faire un singleton pour les loggers.