diff options
author | Damian Minkov <damencho@jitsi.org> | 2011-01-31 07:39:47 +0000 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2011-01-31 07:39:47 +0000 |
commit | 58787d1330ab37a712959e772b22622ac66ba4c0 (patch) | |
tree | 5d96f9e74e18fb79495ad507fe7e7739bf63c128 /src/net/java/sip/communicator/impl/packetlogging | |
parent | 5ca09be958c72cf4be01041f01c4d9fbc69c5f3d (diff) | |
download | jitsi-58787d1330ab37a712959e772b22622ac66ba4c0.zip jitsi-58787d1330ab37a712959e772b22622ac66ba4c0.tar.gz jitsi-58787d1330ab37a712959e772b22622ac66ba4c0.tar.bz2 |
Moves logging configuration in separate bundle and add option to archive and save log files.
Diffstat (limited to 'src/net/java/sip/communicator/impl/packetlogging')
5 files changed, 197 insertions, 682 deletions
diff --git a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingActivator.java b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingActivator.java index cd8c1ed..2be6cdb 100644 --- a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingActivator.java +++ b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingActivator.java @@ -8,19 +8,11 @@ package net.java.sip.communicator.impl.packetlogging; import net.java.sip.communicator.service.configuration.*; import net.java.sip.communicator.service.fileaccess.*; -import net.java.sip.communicator.service.gui.*; -import net.java.sip.communicator.service.neomedia.*; import net.java.sip.communicator.service.packetlogging.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.Logger; import org.osgi.framework.*; -import java.util.*; - -import static net.java.sip.communicator.service.protocol.ProtocolProviderFactory.*; - /** * Creates and registers Packet Logging service into OSGi. * Also handles saving and retrieving configuration options for @@ -58,80 +50,9 @@ public class PacketLoggingActivator private static FileAccessService fileAccessService; /** - * The resource service. - */ - private static ResourceManagementService resourceService; - - /** - * Configuration property for packet logging enabled/disabled. - */ - private final static String PACKET_LOGGING_ENABLED_PROPERTY_NAME - = "net.java.sip.communicator.packetlogging.PACKET_LOGGING_ENABLED"; - - /** - * Configuration property for packet logging for - * sip protocol enabled/disabled. - */ - private final static String PACKET_LOGGING_SIP_ENABLED_PROPERTY_NAME - = "net.java.sip.communicator.packetlogging.PACKET_LOGGING_SIP_ENABLED"; - - /** - * Configuration property for packet logging for - * jabber protocol enabled/disabled. - */ - private final static String PACKET_LOGGING_JABBER_ENABLED_PROPERTY_NAME - = "net.java.sip.communicator.packetlogging.PACKET_LOGGING_JABBER_ENABLED"; - - /** - * Configuration property for packet logging for - * RTP enabled/disabled. - */ - private final static String PACKET_LOGGING_RTP_ENABLED_PROPERTY_NAME - = "net.java.sip.communicator.packetlogging.PACKET_LOGGING_RTP_ENABLED"; - - /** - * Configuration property for packet logging for - * ICE4J enabled/disabled. - */ - private final static String PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME - = "net.java.sip.communicator.packetlogging.PACKET_LOGGING_ICE4J_ENABLED"; - - /** - * Configuration property for packet logging file count. - */ - final static String PACKET_LOGGING_FILE_COUNT_PROPERTY_NAME - = "net.java.sip.communicator.packetlogging.PACKET_LOGGING_FILE_COUNT"; - - /** - * Configuration property for packet logging file size. - */ - final static String PACKET_LOGGING_FILE_SIZE_PROPERTY_NAME - = "net.java.sip.communicator.packetlogging.PACKET_LOGGING_FILE_SIZE"; - - /** - * Is Packet Logging Service enabled. - */ - private static boolean globalLoggingEnabled = true; - - /** - * Is Packet Logging Service enabled for sip protocol. - */ - private static boolean sipLoggingEnabled = true; - - /** - * Is Packet Logging Service enabled for jabber protocol. + * The name of the log dir. */ - private static boolean jabberLoggingEnabled = true; - - /** - * Is Packet Logging Service enabled for rtp. - */ - private static boolean rtpLoggingEnabled = true; - - /** - * Is Packet Logging Service enabled for ice4j. - */ - private static boolean ice4jLoggingEnabled = true; + final static String LOGGING_DIR_NAME = "log"; /** * Creates a PacketLoggingServiceImpl, starts it, and registers it as a @@ -148,32 +69,13 @@ public class PacketLoggingActivator packetLoggingService = new PacketLoggingServiceImpl(); - getPacketLoggingService().start(); - - loadConfig(); + packetLoggingService.start(); bundleContext.registerService(PacketLoggingService.class.getName(), - getPacketLoggingService(), null); + packetLoggingService, null); if (logger.isInfoEnabled()) logger.info("Packet Logging Service ...[REGISTERED]"); - - // Config Form - Dictionary<String, String> packetLoggingProps - = new Hashtable<String, String>(); - packetLoggingProps.put( - ConfigurationForm.FORM_TYPE, - ConfigurationForm.ADVANCED_TYPE); - bundleContext.registerService( - ConfigurationForm.class.getName(), - new LazyConfigurationForm( - PacketLoggingConfigForm.class.getName(), - getClass().getClassLoader(), - null, - "impl.packetlogging.PACKET_LOGGING_CONFIG", - 1200, - true), - packetLoggingProps); } /** @@ -185,39 +87,14 @@ public class PacketLoggingActivator throws Exception { - if(getPacketLoggingService() != null) - getPacketLoggingService().stop(); + if(packetLoggingService != null) + packetLoggingService.stop(); + if (logger.isInfoEnabled()) logger.info("Packet Logging Service ...[STOPPED]"); } /** - * Reads the configurations and loads them. - */ - private void loadConfig() - { - globalLoggingEnabled = getConfigurationService().getBoolean( - PACKET_LOGGING_ENABLED_PROPERTY_NAME, - globalLoggingEnabled); - - sipLoggingEnabled = getConfigurationService().getBoolean( - PACKET_LOGGING_SIP_ENABLED_PROPERTY_NAME, - sipLoggingEnabled); - - jabberLoggingEnabled = getConfigurationService().getBoolean( - PACKET_LOGGING_JABBER_ENABLED_PROPERTY_NAME, - jabberLoggingEnabled); - - rtpLoggingEnabled = getConfigurationService().getBoolean( - PACKET_LOGGING_RTP_ENABLED_PROPERTY_NAME, - rtpLoggingEnabled); - - ice4jLoggingEnabled = getConfigurationService().getBoolean( - PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME, - ice4jLoggingEnabled); - } - - /** * Returns a reference to a ConfigurationService implementation currently * registered in the bundle context or null if no such implementation was * found. @@ -253,157 +130,4 @@ public class PacketLoggingActivator } return fileAccessService; } - - /** - * Returns the <tt>ResourceManagementService</tt> obtained from the - * bundle context. - * - * @return the <tt>ResourceManagementService</tt> obtained from the - * bundle context - */ - public static ResourceManagementService getResourceService() - { - if (resourceService == null) - { - ServiceReference resourceReference - = bundleContext.getServiceReference( - ResourceManagementService.class.getName()); - - resourceService = - (ResourceManagementService) bundleContext - .getService(resourceReference); - } - - return resourceService; - } - - /** - * Checks whether packet logging is enabled in the configuration. - * @return <tt>true</tt> if packet logging is enabled. - */ - public static boolean isGlobalLoggingEnabled() - { - return globalLoggingEnabled; - } - - /** - * Checks whether packet logging is enabled in the configuration - * for sip protocol. - * @return <tt>true</tt> if packet logging is enabled for sip protocol. - */ - public static boolean isSipLoggingEnabled() - { - return sipLoggingEnabled; - } - - /** - * Checks whether packet logging is enabled in the configuration - * for jabber protocol. - * @return <tt>true</tt> if packet logging is enabled for jabber protocol. - */ - public static boolean isJabberLoggingEnabled() - { - return jabberLoggingEnabled; - } - - /** - * Checks whether packet logging is enabled in the configuration - * for RTP. - * @return <tt>true</tt> if packet logging is enabled for RTP. - */ - public static boolean isRTPLoggingEnabled() - { - return rtpLoggingEnabled; - } - - /** - * Checks whether packet logging is enabled in the configuration - * for Ice4J. - * @return <tt>true</tt> if packet logging is enabled for RTP. - */ - public static boolean isIce4JLoggingEnabled() - { - return ice4jLoggingEnabled; - } - - /** - * Change whether packet logging is enabled and save it in configuration. - * @param enabled <tt>true</tt> if we enable it. - */ - static void setGlobalLoggingEnabled(boolean enabled) - { - getConfigurationService().setProperty( - PACKET_LOGGING_ENABLED_PROPERTY_NAME, enabled); - - if(!enabled) - { - // as we are globally off, set it and to services - sipLoggingEnabled = false; - jabberLoggingEnabled = false; - rtpLoggingEnabled = false; - ice4jLoggingEnabled = false; - } - - globalLoggingEnabled = enabled; - } - - /** - * Change whether packet logging for sip protocol is enabled - * and save it in configuration. - * @param enabled <tt>true</tt> if we enable it. - */ - public static void setSipLoggingEnabled(boolean enabled) - { - getConfigurationService().setProperty( - PACKET_LOGGING_SIP_ENABLED_PROPERTY_NAME, enabled); - - sipLoggingEnabled = enabled; - } - - /** - * Change whether packet logging for jabber protocol is enabled - * and save it in configuration. - * @param enabled <tt>true</tt> if we enable it. - */ - public static void setJabberLoggingEnabled(boolean enabled) - { - getConfigurationService().setProperty( - PACKET_LOGGING_JABBER_ENABLED_PROPERTY_NAME, enabled); - - jabberLoggingEnabled = enabled; - } - - /** - * Change whether packet logging for RTP is enabled - * and save it in configuration. - * @param enabled <tt>true</tt> if we enable it. - */ - public static void setRTPLoggingEnabled(boolean enabled) - { - getConfigurationService().setProperty( - PACKET_LOGGING_RTP_ENABLED_PROPERTY_NAME, enabled); - - rtpLoggingEnabled = true; - } - - /** - * Change whether packet logging for Ice4J is enabled - * and save it in configuration. - * @param enabled <tt>true</tt> if we enable it. - */ - public static void setIce4JLoggingEnabled(boolean enabled) - { - getConfigurationService().setProperty( - PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME, enabled); - - ice4jLoggingEnabled = true; - } - - /** - * Our packet logging service instance. - */ - public static PacketLoggingServiceImpl getPacketLoggingService() - { - return packetLoggingService; - } } diff --git a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingConfigForm.java b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingConfigForm.java deleted file mode 100644 index 342c55f..0000000 --- a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingConfigForm.java +++ /dev/null @@ -1,321 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.packetlogging; - -import net.java.sip.communicator.service.resources.*; -import net.java.sip.communicator.util.swing.*; - -import javax.swing.*; -import javax.swing.event.*; -import java.awt.*; -import java.awt.event.*; - -/** - * The Packet Logging Service configuration form. - * @author Damian Minkov - */ -public class PacketLoggingConfigForm - extends TransparentPanel - implements ActionListener, - DocumentListener -{ - /** - * The enable packet logging check box. - */ - private JCheckBox enableCheckBox; - - /** - * Check box to enable/disable packet debug of sip protocol. - */ - private JCheckBox sipProtocolCheckBox; - - /** - * Check box to enable/disable packet debug of jabber protocol. - */ - private JCheckBox jabberProtocolCheckBox; - - /** - * Check box to enable/disable packet debug of media protocol/RTP. - */ - private JCheckBox rtpProtocolCheckBox; - - /** - * Check box to enable/disable packet debug of Ice4J. - */ - private JCheckBox ice4jProtocolCheckBox; - - /** - * The file count label. - */ - private JLabel fileCountLabel; - - /** - * The filed for file count value. - */ - private JTextField fileCountField = new JTextField(); - - /** - * The file size label. - */ - private JLabel fileSizeLabel; - - /** - * The filed for file size value. - */ - private JTextField fileSizeField = new JTextField(); - - - /** - * Creates Packet Logging Config form. - */ - public PacketLoggingConfigForm() - { - super(new BorderLayout()); - - init(); - loadValues(); - } - - /** - * Creating the configuration form - */ - private void init() - { - ResourceManagementService resources = - PacketLoggingActivator.getResourceService(); - - enableCheckBox = new SIPCommCheckBox( - resources.getI18NString("impl.packetlogging.ENABLE_DISABLE")); - enableCheckBox.addActionListener(this); - - sipProtocolCheckBox = new SIPCommCheckBox( - resources.getI18NString("plugin.sipaccregwizz.PROTOCOL_NAME")); - sipProtocolCheckBox.addActionListener(this); - - jabberProtocolCheckBox = new SIPCommCheckBox( - resources.getI18NString("plugin.jabberaccregwizz.PROTOCOL_NAME")); - jabberProtocolCheckBox.addActionListener(this); - - String rtpDescription = resources.getI18NString( - "impl.packetlogging.PACKET_LOGGING_RTP_DESCRIPTION"); - rtpProtocolCheckBox = new SIPCommCheckBox( - resources.getI18NString("impl.packetlogging.PACKET_LOGGING_RTP") - + " " + rtpDescription); - rtpProtocolCheckBox.addActionListener(this); - rtpProtocolCheckBox.setToolTipText(rtpDescription); - - ice4jProtocolCheckBox = new SIPCommCheckBox( - resources.getI18NString("impl.packetlogging.PACKET_LOGGING_ICE4J")); - ice4jProtocolCheckBox.addActionListener(this); - - JPanel mainPanel = new TransparentPanel(); - - add(mainPanel, BorderLayout.NORTH); - - mainPanel.setLayout(new GridBagLayout()); - - GridBagConstraints c = new GridBagConstraints(); - - enableCheckBox.setAlignmentX(Component.LEFT_ALIGNMENT); - - c.fill = GridBagConstraints.HORIZONTAL; - c.weightx = 1.0; - c.gridx = 0; - c.gridy = 0; - mainPanel.add(enableCheckBox, c); - - String label = resources.getI18NString( - "impl.packetlogging.PACKET_LOGGING_DESCRIPTION"); - JLabel descriptionLabel = new JLabel(label); - descriptionLabel.setToolTipText(label); - enableCheckBox.setToolTipText(label); - descriptionLabel.setForeground(Color.GRAY); - descriptionLabel.setFont(descriptionLabel.getFont().deriveFont(8)); - c.gridy = 1; - c.insets = new Insets(0, 25, 10, 0); - mainPanel.add(descriptionLabel, c); - - final JPanel loggersButtonPanel - = new TransparentPanel(new GridLayout(0, 1)); - - loggersButtonPanel.setBorder(BorderFactory.createTitledBorder( - resources.getI18NString("service.gui.PROTOCOL"))); - - loggersButtonPanel.add(sipProtocolCheckBox); - loggersButtonPanel.add(jabberProtocolCheckBox); - loggersButtonPanel.add(rtpProtocolCheckBox); - loggersButtonPanel.add(ice4jProtocolCheckBox); - - c.insets = new Insets(0, 20, 10, 0); - c.gridy = 2; - mainPanel.add(loggersButtonPanel, c); - - final JPanel advancedPanel - = new TransparentPanel(new GridLayout(0, 2)); - - advancedPanel.setBorder(BorderFactory.createTitledBorder( - resources.getI18NString("service.gui.ADVANCED"))); - - fileCountField.getDocument().addDocumentListener(this); - fileSizeField.getDocument().addDocumentListener(this); - - fileCountLabel = new JLabel(resources.getI18NString( - "impl.packetlogging.PACKET_LOGGING_FILE_COUNT")); - advancedPanel.add(fileCountLabel); - advancedPanel.add(fileCountField); - fileSizeLabel = new JLabel(resources.getI18NString( - "impl.packetlogging.PACKET_LOGGING_FILE_SIZE")); - advancedPanel.add(fileSizeLabel); - advancedPanel.add(fileSizeField); - - c.gridy = 3; - mainPanel.add(advancedPanel, c); - - } - - /** - * Loading the values stored into configuration form - */ - private void loadValues() - { - enableCheckBox.setSelected( - PacketLoggingActivator.isGlobalLoggingEnabled()); - sipProtocolCheckBox.setSelected( - PacketLoggingActivator.isSipLoggingEnabled()); - jabberProtocolCheckBox.setSelected( - PacketLoggingActivator.isJabberLoggingEnabled()); - rtpProtocolCheckBox.setSelected( - PacketLoggingActivator.isRTPLoggingEnabled()); - ice4jProtocolCheckBox.setSelected( - PacketLoggingActivator.isIce4JLoggingEnabled()); - fileCountField.setText(String.valueOf(PacketLoggingActivator - .getPacketLoggingService().getLogfileCount())); - fileSizeField.setText(String.valueOf(PacketLoggingActivator - .getPacketLoggingService().getLimit()/1000)); - - updateButtonsState(); - } - - /** - * Update button enable/disable state according enableCheckBox. - */ - private void updateButtonsState() - { - sipProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); - jabberProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); - rtpProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); - ice4jProtocolCheckBox.setEnabled(enableCheckBox.isSelected()); - fileCountField.setEnabled(enableCheckBox.isSelected()); - fileSizeField.setEnabled(enableCheckBox.isSelected()); - fileSizeLabel.setEnabled(enableCheckBox.isSelected()); - fileCountLabel.setEnabled(enableCheckBox.isSelected()); - } - - /** - * Invoked when an action occurs. - */ - public void actionPerformed(ActionEvent e) - { - Object source = e.getSource(); - - if(source.equals(enableCheckBox)) - { - // turn it on/off in activator - PacketLoggingActivator.setGlobalLoggingEnabled( - enableCheckBox.isSelected()); - updateButtonsState(); - } - else if(source.equals(sipProtocolCheckBox)) - { - PacketLoggingActivator.setSipLoggingEnabled( - sipProtocolCheckBox.isSelected()); - } - else if(source.equals(jabberProtocolCheckBox)) - { - PacketLoggingActivator.setJabberLoggingEnabled( - jabberProtocolCheckBox.isSelected()); - } - else if(source.equals(rtpProtocolCheckBox)) - { - PacketLoggingActivator.setRTPLoggingEnabled( - rtpProtocolCheckBox.isSelected()); - } - else if(source.equals(ice4jProtocolCheckBox)) - { - PacketLoggingActivator.setIce4JLoggingEnabled( - ice4jProtocolCheckBox.isSelected()); - } - } - - /** - * Gives notification that there was an insert into the document. The - * range given by the DocumentEvent bounds the freshly inserted region. - * - * @param e the document event - */ - public void insertUpdate(DocumentEvent e) - { - documentChanged(e); - } - - /** - * Gives notification that a portion of the document has been - * removed. The range is given in terms of what the view last - * saw (that is, before updating sticky positions). - * - * @param e the document event - */ - public void removeUpdate(DocumentEvent e) - { - documentChanged(e); - } - - /** - * Not used. - * - * @param e the document event - */ - public void changedUpdate(DocumentEvent e) - {} - - /** - * A change in the text fields. - * @param e the document event. - */ - private void documentChanged(DocumentEvent e) - { - if(e.getDocument().equals(fileCountField.getDocument())) - { - // set file count only if its un integer - try - { - int newFileCount = Integer.valueOf(fileCountField.getText()); - fileCountField.setForeground(Color.black); - PacketLoggingActivator.getPacketLoggingService() - .setLogfileCount(newFileCount); - } - catch(Throwable t) - { - fileCountField.setForeground(Color.red); - } - } - else if(e.getDocument().equals(fileSizeField.getDocument())) - { - // set file size only if its un integer - try - { - int newFileSize = Integer.valueOf(fileSizeField.getText()); - fileSizeField.setForeground(Color.black); - PacketLoggingActivator.getPacketLoggingService() - .setLimit(newFileSize * 1000); - } - catch(Throwable t) - { - fileSizeField.setForeground(Color.red); - } - } - } -} diff --git a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingConfigurationImpl.java b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingConfigurationImpl.java new file mode 100644 index 0000000..be2b2ab --- /dev/null +++ b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingConfigurationImpl.java @@ -0,0 +1,155 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.packetlogging; + +import net.java.sip.communicator.service.configuration.*; +import net.java.sip.communicator.service.packetlogging.*; + +/** + * Extends PacketLoggingConfiguration by storing and loading values from + * configuration service. + * + * @author Damian Minkov + */ +public class PacketLoggingConfigurationImpl + extends PacketLoggingConfiguration +{ + /** + * Creates new PacketLoggingConfiguration and load values from + * configuration service and if missing uses already defined + * default values. + */ + PacketLoggingConfigurationImpl() + { + // load values from config service + ConfigurationService configService = + PacketLoggingActivator.getConfigurationService(); + + super.setGlobalLoggingEnabled( + configService.getBoolean( + PACKET_LOGGING_ENABLED_PROPERTY_NAME, + isGlobalLoggingEnabled())); + super.setSipLoggingEnabled( + configService.getBoolean( + PACKET_LOGGING_SIP_ENABLED_PROPERTY_NAME, + isSipLoggingEnabled())); + super.setJabberLoggingEnabled( + configService.getBoolean( + PACKET_LOGGING_JABBER_ENABLED_PROPERTY_NAME, + isJabberLoggingEnabled())); + super.setRTPLoggingEnabled( + configService.getBoolean( + PACKET_LOGGING_RTP_ENABLED_PROPERTY_NAME, + isRTPLoggingEnabled())); + super.setIce4JLoggingEnabled( + configService.getBoolean( + PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME, + isIce4JLoggingEnabled())); + super.setLimit( + configService.getLong( + PACKET_LOGGING_FILE_SIZE_PROPERTY_NAME, + getLimit())); + super.setLogfileCount( + configService.getInt( + PACKET_LOGGING_FILE_COUNT_PROPERTY_NAME, + getLogfileCount())); + } + + /** + * Change whether packet logging is enabled and save it in configuration. + * @param enabled <tt>true</tt> if we enable it. + */ + public void setGlobalLoggingEnabled(boolean enabled) + { + super.setGlobalLoggingEnabled(enabled); + + PacketLoggingActivator.getConfigurationService().setProperty( + PACKET_LOGGING_ENABLED_PROPERTY_NAME, enabled); + } + + /** + * Change whether packet logging for sip protocol is enabled + * and save it in configuration. + * @param enabled <tt>true</tt> if we enable it. + */ + public void setSipLoggingEnabled(boolean enabled) + { + super.setSipLoggingEnabled(enabled); + + PacketLoggingActivator.getConfigurationService().setProperty( + PACKET_LOGGING_SIP_ENABLED_PROPERTY_NAME, + enabled); + } + + /** + * Change whether packet logging for jabber protocol is enabled + * and save it in configuration. + * @param enabled <tt>true</tt> if we enable it. + */ + public void setJabberLoggingEnabled(boolean enabled) + { + super.setJabberLoggingEnabled(enabled); + + PacketLoggingActivator.getConfigurationService().setProperty( + PACKET_LOGGING_JABBER_ENABLED_PROPERTY_NAME, + enabled); + } + + /** + * Change whether packet logging for RTP is enabled + * and save it in configuration. + * @param enabled <tt>true</tt> if we enable it. + */ + public void setRTPLoggingEnabled(boolean enabled) + { + super.setRTPLoggingEnabled(enabled); + + PacketLoggingActivator.getConfigurationService().setProperty( + PACKET_LOGGING_RTP_ENABLED_PROPERTY_NAME, + enabled); + } + + /** + * Change whether packet logging for Ice4J is enabled + * and save it in configuration. + * @param enabled <tt>true</tt> if we enable it. + */ + public void setIce4JLoggingEnabled(boolean enabled) + { + super.setIce4JLoggingEnabled(enabled); + + PacketLoggingActivator.getConfigurationService().setProperty( + PACKET_LOGGING_ICE4J_ENABLED_PROPERTY_NAME, + enabled); + } + + /** + * Changes the file size limit. + * @param limit the new limit size. + */ + public void setLimit(long limit) + { + super.setLimit(limit); + + PacketLoggingActivator.getConfigurationService().setProperty( + PACKET_LOGGING_FILE_SIZE_PROPERTY_NAME, + limit); + } + + /** + * Changes file count. + * @param logfileCount the new file count. + */ + public void setLogfileCount(int logfileCount) + { + super.setLogfileCount(logfileCount); + + PacketLoggingActivator.getConfigurationService().setProperty( + PACKET_LOGGING_FILE_COUNT_PROPERTY_NAME, + logfileCount); + } +} diff --git a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java index e1905b4..d0615bf 100644 --- a/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java +++ b/src/net/java/sip/communicator/impl/packetlogging/PacketLoggingServiceImpl.java @@ -38,6 +38,11 @@ public class PacketLoggingServiceImpl private SaverThread saverThread = new SaverThread(); /** + * The current configuration. + */ + private PacketLoggingConfiguration packetLoggingConfiguration = null; + + /** * The fake ethernet header we use as template. */ private final static byte[] fakeEthernetHeader = @@ -133,17 +138,6 @@ public class PacketLoggingServiceImpl private long written = 0; /** - * The limit for the file size. - * 0 means no limit. - */ - private long limit = 5000000; - - /** - * The counter for number of files. - */ - private int logfileCount = 3; - - /** * All the files we can use for writing. */ private File[] files; @@ -154,14 +148,6 @@ public class PacketLoggingServiceImpl */ public void start() { - limit = PacketLoggingActivator.getConfigurationService().getLong( - PacketLoggingActivator.PACKET_LOGGING_FILE_SIZE_PROPERTY_NAME, - limit); - - logfileCount = PacketLoggingActivator.getConfigurationService().getInt( - PacketLoggingActivator.PACKET_LOGGING_FILE_COUNT_PROPERTY_NAME, - logfileCount); - saverThread.start(); } @@ -172,11 +158,13 @@ public class PacketLoggingServiceImpl private void getFileNames() throws Exception { - files = new File[getLogfileCount()]; - for(int i = 0; i < getLogfileCount(); i++) + files = new File[getConfiguration().getLogfileCount()]; + for(int i = 0; i < getConfiguration().getLogfileCount(); i++) { files[i] = PacketLoggingActivator.getFileAccessService() - .getPrivatePersistentFile("log/sip-communicator" + i + ".pcap"); + .getPrivatePersistentFile( + PacketLoggingActivator.LOGGING_DIR_NAME + + File.separator + "sip-communicator" + i + ".pcap"); } } @@ -194,7 +182,7 @@ public class PacketLoggingServiceImpl outputStream.close(); } - for (int i = getLogfileCount() -2; i >= 0; i--) + for (int i = getConfiguration().getLogfileCount() -2; i >= 0; i--) { File f1 = files[i]; File f2 = files[i+1]; @@ -288,7 +276,7 @@ public class PacketLoggingServiceImpl */ public boolean isLoggingEnabled() { - return PacketLoggingActivator.isGlobalLoggingEnabled(); + return getConfiguration().isGlobalLoggingEnabled(); } /** @@ -303,17 +291,17 @@ public class PacketLoggingServiceImpl switch(protocol) { case SIP: - return PacketLoggingActivator.isGlobalLoggingEnabled() - && PacketLoggingActivator.isSipLoggingEnabled(); + return getConfiguration().isGlobalLoggingEnabled() + && getConfiguration().isSipLoggingEnabled(); case JABBER: - return PacketLoggingActivator.isGlobalLoggingEnabled() - && PacketLoggingActivator.isJabberLoggingEnabled(); + return getConfiguration().isGlobalLoggingEnabled() + && getConfiguration().isJabberLoggingEnabled(); case RTP: - return PacketLoggingActivator.isGlobalLoggingEnabled() - && PacketLoggingActivator.isRTPLoggingEnabled(); + return getConfiguration().isGlobalLoggingEnabled() + && getConfiguration().isRTPLoggingEnabled(); case ICE4J: - return PacketLoggingActivator.isGlobalLoggingEnabled() - && PacketLoggingActivator.isIce4JLoggingEnabled(); + return getConfiguration().isGlobalLoggingEnabled() + && getConfiguration().isIce4JLoggingEnabled(); default: return false; } @@ -385,6 +373,19 @@ public class PacketLoggingServiceImpl } /** + * Returns the current Packet Logging Configuration. + * + * @return the Packet Logging Configuration. + */ + public PacketLoggingConfiguration getConfiguration() + { + if(packetLoggingConfiguration == null) + packetLoggingConfiguration = new PacketLoggingConfigurationImpl(); + + return packetLoggingConfiguration; + } + + /** * Dump the packet to the output file stream. * * @param packet the packet ot save. @@ -537,7 +538,8 @@ public class PacketLoggingServiceImpl rotateFiles();// this one opens the file for write } - if(getLimit() > 0 && written > getLimit()) + if(getConfiguration().getLimit() > 0 + && written > getConfiguration().getLimit()) rotateFiles(); addInt(tsSec); @@ -628,50 +630,6 @@ public class PacketLoggingServiceImpl } /** - * The limit for the file size. 0 means no limit. - * @return the file size limit. - */ - public long getLimit() - { - return limit; - } - - /** - * Changes the file size limit. - * @param limit the new limit size. - */ - public void setLimit(long limit) - { - this.limit = limit; - - PacketLoggingActivator.getConfigurationService().setProperty( - PacketLoggingActivator.PACKET_LOGGING_FILE_SIZE_PROPERTY_NAME, - limit); - } - - /** - * The counter for number of files. - * @return the number of file counts. - */ - public int getLogfileCount() - { - return logfileCount; - } - - /** - * Changes file count. - * @param logfileCount the new file count. - */ - public void setLogfileCount(int logfileCount) - { - this.logfileCount = logfileCount; - - PacketLoggingActivator.getConfigurationService().setProperty( - PacketLoggingActivator.PACKET_LOGGING_FILE_COUNT_PROPERTY_NAME, - logfileCount); - } - - /** * The data we receive and that we will dump in a file. */ private class Packet diff --git a/src/net/java/sip/communicator/impl/packetlogging/packetlogging.manifest.mf b/src/net/java/sip/communicator/impl/packetlogging/packetlogging.manifest.mf index 593c203..7cdd3b7 100644 --- a/src/net/java/sip/communicator/impl/packetlogging/packetlogging.manifest.mf +++ b/src/net/java/sip/communicator/impl/packetlogging/packetlogging.manifest.mf @@ -10,7 +10,6 @@ Import-Package: org.osgi.framework, net.java.sip.communicator.service.gui, net.java.sip.communicator.service.neomedia, net.java.sip.communicator.service.protocol, - net.java.sip.communicator.service.resources, net.java.sip.communicator.util, net.java.sip.communicator.util.swing, javax.swing, |