From 821d52e3694fac0b907ec240e264f4d52d352966 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 19 Jan 2013 21:24:22 +0100 Subject: Allow 'joinMessage' to include actual log URL, notify @ each logrotate - joinMessage configurable - Add config: urlprefix (same as logprefix, but in URL space) - Set bot's joinMessage: joinMessage + urlprefix + current logfile - Notify new logfile via logged joinMessage in old and new logfile and channel itself --- scripts/jogamp-log02.sh | 1 + scripts/start.jabot.sh | 1 + src/org/jogamp/jabot/irc/CatOut.java | 112 ++++++++++++++++++++++------------- src/org/jogamp/jabot/irc/LogBot.java | 32 +++++++++- 4 files changed, 101 insertions(+), 45 deletions(-) diff --git a/scripts/jogamp-log02.sh b/scripts/jogamp-log02.sh index 42a6c2d..09d1c0c 100755 --- a/scripts/jogamp-log02.sh +++ b/scripts/jogamp-log02.sh @@ -8,6 +8,7 @@ java -cp build/jabot.jar org.jogamp.jabot.irc.CatOut \ -logrotate 60000 \ -logrotateStart 0736 \ -logprefix "log/irc/" \ + -urlprefix "file:///usr/local/projects/JOGL/bots/jabot/log/irc/" \ -htmlHeader assets/header.html \ -htmlFooter assets/footer.html \ >& $LOGFILE diff --git a/scripts/start.jabot.sh b/scripts/start.jabot.sh index 46a9bd6..7b60709 100755 --- a/scripts/start.jabot.sh +++ b/scripts/start.jabot.sh @@ -11,6 +11,7 @@ nohup nice $JAVA \ -logrotate 86400000 \ -logrotateStart 0505 \ -logprefix "/home/jogl/jogamp.org/log/irc/" \ + -urlprefix "http://jogamp.org/log/irc/" \ -htmlHeader $JABOT_HOME/assets/header.html \ -htmlFooter $JABOT_HOME/assets/footer.html \ > $JABOT_LOG 2>&1 & diff --git a/src/org/jogamp/jabot/irc/CatOut.java b/src/org/jogamp/jabot/irc/CatOut.java index f6812af..3e494de 100644 --- a/src/org/jogamp/jabot/irc/CatOut.java +++ b/src/org/jogamp/jabot/irc/CatOut.java @@ -36,23 +36,27 @@ public class CatOut extends PircBot { } public static void main(String[] args) throws Exception { - final String joinMessage = "This channel is logged"; + final String joinMessage; final boolean showHostname = false; final String login, name, server, channelNoHash; final boolean verbose; final long logrotate, logrotateStart; - final String logprefix; + final String logprefix, urlprefix; final boolean htmlOut; final File htmlHeader, htmlFooter; { + String _joinMessage = "This channel is logged"; String _login=null, _name=null, _server=null, _channelNoHash=null; boolean _verbose=false; long _logrotate = 0, _logrotateStart=System.currentTimeMillis(); - String _logprefix=""; + String _logprefix="", _urlprefix=""; boolean _htmlOut = false; String _htmlHeader = null, _htmlFooter=null; for(int i=0; i= nextLogrotate ) { // Swap Logfiles: Open and set new logfile, then close old one. - final PrintStream _fout = createLogStream(bot, logprefix, server, channelNoHash, htmlHeader); - bot.setOut(_fout, true); + final LogStream _logOut = new LogStream(bot, logprefix, urlprefix, server, channelNoHash, htmlHeader); + bot.logNotice("Continue @ "+_logOut.urlString); + bot.setOut(_logOut.out, true); + bot.setJoinMessage(joinMessage+" @ "+_logOut.urlString); + bot.sendLoggedNotice(HASH+channelNoHash, bot.getJoinMessage()); if(htmlOut) { - cat(htmlFooter, fout); + logOut.cat(htmlFooter); } - fout.close(); // implies flush - fout = _fout; + logOut.close(); // implies flush + logOut = _logOut; nextLogrotate += logrotate; logCal.setTimeInMillis(now); System.err.println("Now : "+logCal.getTime()); @@ -167,41 +181,55 @@ public class CatOut extends PircBot { try { Thread.sleep(FLUSH_INTERVAL); } catch (Exception e) { } - if(null != fout) { - fout.flush(); + if(null != logOut) { + logOut.flush(); } } } } public static final long FLUSH_INTERVAL = 60*1000; // flush every minute + + static class LogStream { + public final PrintStream out; + public final String fileName; + public final String urlString; + + public LogStream(final LogBot bot, String logprefix, String urlprefix, String serverName, String channelName, File htmlHeader) throws Exception { + final Calendar calendar = bot.tick(); + final String suffix = null != htmlHeader ? ".html" : ".txt" ; + final String baseName = channelName+"_"+TimeTool.getTimeStamp(calendar, true, false)+suffix; + fileName = logprefix+baseName; + urlString = urlprefix+baseName; + final File _file = new File(fileName); + out = new PrintStream(new FileOutputStream(_file)); + if(null != htmlHeader) { + cat(htmlHeader); + htmlHead(HASH+channelName+" @ "+serverName+" - "+bot.getTimeStamp()+" ("+calendar.getTimeZone().getID()+")"); + } + } + public void flush() { + out.flush(); + } + public void close() { + out.close(); + } - private static PrintStream createLogStream(final LogBot bot, String logprefix, String serverName, String channelName, File htmlHeader) throws Exception { - final Calendar calendar = bot.tick(); - final String suffix = null != htmlHeader ? ".html" : ".txt" ; - final String logfilename = logprefix+channelName+"_"+TimeTool.getTimeStamp(calendar, true, false)+suffix; - final File _file = new File(logfilename); - final PrintStream _fout = new PrintStream(new FileOutputStream(_file)); - if(null != htmlHeader) { - cat(htmlHeader, _fout); - htmlHead(HASH+channelName+" @ "+serverName+" - "+bot.getTimeStamp()+" ("+calendar.getTimeZone().getID()+")", - _fout); + public void cat(File source) throws IOException { + final BufferedInputStream input = new BufferedInputStream(new FileInputStream(source)); + int bytesRead = 0; + byte[] buffer = new byte[1024]; + while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1) { + out.write(buffer, 0, bytesRead); + } + out.flush(); + input.close(); } - return _fout; - } - - public static void cat(File source, PrintStream out) throws IOException { - final BufferedInputStream input = new BufferedInputStream(new FileInputStream(source)); - int bytesRead = 0; - byte[] buffer = new byte[1024]; - while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1) { - out.write(buffer, 0, bytesRead); + + private void htmlHead(String head) { + out.println("

"+head+"

"); + out.println("
"); + out.flush(); } - out.flush(); - input.close(); - } - public static void htmlHead(String head, PrintStream out) { - out.println("

"+head+"

"); - out.println("
"); - out.flush(); } + } diff --git a/src/org/jogamp/jabot/irc/LogBot.java b/src/org/jogamp/jabot/irc/LogBot.java index 9c085a2..a4d143f 100644 --- a/src/org/jogamp/jabot/irc/LogBot.java +++ b/src/org/jogamp/jabot/irc/LogBot.java @@ -31,7 +31,7 @@ public class LogBot extends PircBot { public static final String BRICK = "irc-brick"; public static final String RED = "irc-red"; - private static final Pattern urlPattern = Pattern.compile("(?i:\\b((http|https|ftp|irc)://[^\\s]+))"); + private static final Pattern urlPattern = Pattern.compile("(?i:\\b((http|https|ftp|irc|file)://[^\\s]+))"); private static String ANONYMOUS = "anon"; private final boolean showHostname; @@ -58,6 +58,13 @@ public class LogBot extends PircBot { this.lineCount = 0; } + public final void setJoinMessage(String joinMessage) { + this.joinMessage = joinMessage; + } + public final String getJoinMessage() { + return joinMessage; + } + public final void setLoginAndName(String login, String nick) { super.setLogin(login); super.setName(nick); @@ -141,6 +148,26 @@ public class LogBot extends PircBot { } + /** + * Log a notice + * + * @param notice The notice to log. + */ + public final void logNotice(String notice) { + append(BROWN, "-" + getNick() + "- " + notice); + } + + /** + * Sends a logged notice to the channel or to a user. + * + * @param target The name of the channel or user nick to send to. + * @param notice The notice to send. + */ + public final void sendLoggedNotice(String target, String notice) { + super.sendNotice(target, notice); + append(BROWN, "-" + getNick() + "- " + notice); + } + public void onAction(String sender, String login, String hostname, String target, String action) { append(BRICK, "* " + sender + " " + action); } @@ -149,8 +176,7 @@ public class LogBot extends PircBot { append(GREEN, "* " + sender + " (" + login + "@" + ( showHostname ? hostname : ANONYMOUS ) + ") has joined " + channel); if (sender.equals(getNick())) { sendNotice(channel, joinMessage); - } - else { + } else { sendNotice(sender, joinMessage); } } -- cgit v1.2.3