2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.server;
21 import java.io.IOException;
22 import java.util.concurrent.BlockingQueue;
23 import java.util.concurrent.TimeUnit;
25 import org.eclipse.jetty.util.BlockingArrayQueue;
26 import org.eclipse.jetty.util.log.Log;
27 import org.eclipse.jetty.util.log.Logger;
30 /* ------------------------------------------------------------ */
32 * An asynchronously writing NCSA Request Log
34 public class AsyncNCSARequestLog extends NCSARequestLog
36 private static final Logger LOG = Log.getLogger(AsyncNCSARequestLog.class);
37 private final BlockingQueue<String> _queue;
38 private transient WriterThread _thread;
39 private boolean _warnedFull;
41 public AsyncNCSARequestLog()
46 public AsyncNCSARequestLog(BlockingQueue<String> queue)
51 public AsyncNCSARequestLog(String filename)
56 public AsyncNCSARequestLog(String filename,BlockingQueue<String> queue)
60 queue=new BlockingArrayQueue<>(1024);
64 private class WriterThread extends Thread
68 setName("AsyncNCSARequestLog@"+Integer.toString(AsyncNCSARequestLog.this.hashCode(),16));
78 String log = _queue.poll(10,TimeUnit.SECONDS);
80 AsyncNCSARequestLog.super.write(log);
82 while(!_queue.isEmpty())
86 AsyncNCSARequestLog.super.write(log);
93 catch (InterruptedException e)
102 protected synchronized void doStart() throws Exception
105 _thread = new WriterThread();
110 protected void doStop() throws Exception
119 public void write(String log) throws IOException
121 if (!_queue.offer(log))
124 LOG.warn("Log Queue overflow");