Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail From: JLP Newsgroups: comp.lang.java.programmer Subject: Re: Tailing a series of log files Date: Sat, 15 Jun 2013 18:59:05 +0200 Organization: Aioe.org NNTP Server Lines: 31 Message-ID: References: <3f65c1bd-6589-4b87-b6a9-646250731faa@googlegroups.com> NNTP-Posting-Host: LvQ2l3zbWZ7olCiRjPbj0g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:24413 Le 15/06/2013 15:20, Eric Sosman a écrit : > On 6/15/2013 12:11 AM, Daniel Pitts wrote: >> On 6/14/13 6:06 PM, Eric Sosman wrote: >>> On 6/14/2013 7:00 PM, Arved Sandstrom wrote: >>>> On 06/12/2013 09:04 AM, SamXiao wrote: >>>>> Hi all, >>>>> >>>>> I am working on a solution to keep track of a series of log files and >>>>> read the tail lines. At the very beginning, there is only one log file >>>>> named “TEST-YYYYMMDD-00.log” (where YYYYMMDD is the current date). >>>>> When the size of this log reaches to 10 MB, another log file >>>>> “TEST-YYYYMMDD-01.log” will be generated and so forth. After midnight >>>>> (12:00), a new log file with the next date starting with 00 again will >>>>> be generated. >>>>> >>>>> I know Apache Commons IO containing tail.java. However, seems it is >>>>> for tailing a single log file only. How could I keep tailing a series >>>>> of log files? >>>>> >>> [SNIP because of NNTP server] > if I understand the OP requirements, a solution may be the pattern Observer/Observable : - a thread Observable that follows the creation of file TEST-[\d]{6}(-[^\.])?.log . When a new file is created motify the thread Observer with the new file log - a thread Observer subscribed to the Observable that tails the last file log and rotate when notified http://en.wikipedia.org/wiki/Observer_pattern