View Javadoc

1   // ========================================================================
2   // Copyright (c) Webtide LLC
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  
15  package org.eclipse.jetty.monitor.jmx;
16  
17  import org.eclipse.jetty.util.log.Log;
18  import org.eclipse.jetty.util.log.Logger;
19  
20  
21  /* ------------------------------------------------------------ */
22  /**
23   * ConsoleNotifier
24   * 
25   * Provides a way to output notification messages to a log file
26   */
27  public class LoggingNotifier implements EventNotifier
28  {
29      private static final Logger LOG = Log.getLogger(LoggingNotifier.class);
30  
31      String _messageFormat;
32  
33      /* ------------------------------------------------------------ */
34      /**
35       * Constructs a new notifier with specified format string
36       * 
37       * @param format the {@link java.util.Formatter format string}
38       * @throws IllegalArgumentException
39       */
40      public LoggingNotifier(String format)
41          throws IllegalArgumentException
42      {
43          if (format == null)
44              throw new IllegalArgumentException("Message format cannot be null");
45          
46          _messageFormat = format;
47      }
48      
49      /* ------------------------------------------------------------ */
50      /**
51       * @see org.eclipse.jetty.monitor.jmx.EventNotifier#notify(org.eclipse.jetty.monitor.jmx.EventTrigger, org.eclipse.jetty.monitor.jmx.EventState, long)
52       */
53      public void notify(EventTrigger trigger, EventState<?> state, long timestamp)
54      {
55          String output = String.format(_messageFormat, state);
56          
57          LOG.info(output);
58      }
59  
60  }