aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java
blob: a10a6322abd33167a3bb5fed9f653c7eda5874d5 (plain)
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
/*
 * 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.notification;

import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.util.*;

/**
 * An implementation of the <tt>LogMessageNotificationHandler</tt> interface.
 * 
 * @author Yana Stamcheva
 */
public class LogMessageNotificationHandlerImpl
    implements LogMessageNotificationHandler
{
    /**
     * The logger that will be used to log messages.
     */
    private Logger logger
        = Logger.getLogger(LogMessageNotificationHandlerImpl.class);

    private String logType;

    private boolean isEnabled = true;

    /**
     * Creates an instance of <tt>LogMessageNotificationHandlerImpl</tt> by
     * specifying the log type.
     * 
     * @param logType the type of the log
     */
    public LogMessageNotificationHandlerImpl(String logType)
    {
        this.logType = logType;
    }
    
    /**
     * Returns the type of the log
     * 
     * @return the type of the log
     */
    public String getLogType()
    {
        return logType;
    }

    /**
     * Logs a message through the sip communicator Logger.
     * 
     * @param message the message coming from the event
     */
    public void logMessage(String message)
    {
        if (logType.equals(LogMessageNotificationHandler.ERROR_LOG_TYPE))
            logger.error(message);
        else if(logType.equals(LogMessageNotificationHandler.INFO_LOG_TYPE))
            if (logger.isInfoEnabled())
                logger.info(message);
        else if(logType.equals(LogMessageNotificationHandler.TRACE_LOG_TYPE))
            if (logger.isTraceEnabled())
                logger.trace(message);
    }

    /**
     * Returns TRUE if this notification action handler is enabled and FALSE
     * otherwise. While the notification handler for the log message action type
     * is disabled no messages will be logged when the
     * <tt>fireNotification</tt> method is called.
     * 
     * @return TRUE if this notification action handler is enabled and FALSE
     * otherwise
     */
    public boolean isEnabled()
    {
        return isEnabled;
    }

    /**
     * Enables or disables this notification handler. While the notification
     * handler for the log message action type is disabled no messages will be
     * logged when the <tt>fireNotification</tt> method is called.
     * 
     * @param isEnabled TRUE to enable this notification handler, FALSE to
     * disable it.
     */
    public void setEnabled(boolean isEnabled)
    {
        this.isEnabled = isEnabled;
    }
}