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
celui de la classe de test
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 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 partie du programme ou ca marche pas
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 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) { } } }
dans le cas ou ca marche pas je passe bien dans toutes mes fonctions appelées mais les 2 commandes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 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(); } }
ne se deroule pas?????
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 logger.addAppender(appender); logger.debug(appender);
et la je sais pas pourquoi ..
help me please
Partager