forked from jetty/jetty.project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue jetty#113 - Added Request Log Writers
Introduced the RequestLog.Writer where a RequestLog takes a writer which manages what to do with the log strings produced by the RequestLog deprecated the NCSA and SLF4J RequestLogs in favor of CustomRequestLog Implemented more format codes in CustomRequestLog Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
- Loading branch information
1 parent
7dd3cff
commit e4d30b3
Showing
9 changed files
with
623 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
jetty-server/src/main/java/org/eclipse/jetty/server/AsyncRequestLogWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.eclipse.jetty.server; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.eclipse.jetty.util.BlockingArrayQueue; | ||
import org.eclipse.jetty.util.log.Log; | ||
import org.eclipse.jetty.util.log.Logger; | ||
|
||
public class AsyncRequestLogWriter extends RequestLogWriter | ||
{ | ||
private static final Logger LOG = Log.getLogger(AsyncRequestLogWriter.class); | ||
private final BlockingQueue<String> _queue; | ||
private transient AsyncRequestLogWriter.WriterThread _thread; | ||
private boolean _warnedFull; | ||
|
||
public AsyncRequestLogWriter() | ||
{ | ||
this(null, null); | ||
} | ||
|
||
public AsyncRequestLogWriter(String filename,BlockingQueue<String> queue) | ||
{ | ||
super(filename); | ||
if (queue==null) | ||
queue=new BlockingArrayQueue<>(1024); | ||
_queue=queue; | ||
} | ||
|
||
private class WriterThread extends Thread | ||
{ | ||
WriterThread() | ||
{ | ||
setName("AsyncRequestLogWriter@"+Integer.toString(AsyncRequestLogWriter.this.hashCode(),16)); | ||
} | ||
|
||
@Override | ||
public void run() | ||
{ | ||
while (isRunning()) | ||
{ | ||
try | ||
{ | ||
String log = _queue.poll(10, TimeUnit.SECONDS); | ||
if (log!=null) | ||
AsyncRequestLogWriter.super.write(log); | ||
|
||
while(!_queue.isEmpty()) | ||
{ | ||
log=_queue.poll(); | ||
if (log!=null) | ||
AsyncRequestLogWriter.super.write(log); | ||
} | ||
} | ||
catch (IOException e) | ||
{ | ||
LOG.warn(e); | ||
} | ||
catch (InterruptedException e) | ||
{ | ||
LOG.ignore(e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected synchronized void doStart() throws Exception | ||
{ | ||
super.doStart(); | ||
_thread = new AsyncRequestLogWriter.WriterThread(); | ||
_thread.start(); | ||
} | ||
|
||
@Override | ||
protected void doStop() throws Exception | ||
{ | ||
_thread.interrupt(); | ||
_thread.join(); | ||
super.doStop(); | ||
_thread=null; | ||
} | ||
|
||
@Override | ||
public void write(String log) throws IOException | ||
{ | ||
if (!_queue.offer(log)) | ||
{ | ||
if (_warnedFull) | ||
LOG.warn("Log Queue overflow"); | ||
_warnedFull=true; | ||
} | ||
} | ||
} |
Oops, something went wrong.