summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-01-19 21:24:22 +0100
committerSven Gothel <[email protected]>2013-01-19 21:24:22 +0100
commit821d52e3694fac0b907ec240e264f4d52d352966 (patch)
treeac79120fb5550e0e4e6bc7688cb3597b36096698
parent60ccfc5ff7dee58740ba1302626e3ccea35259b9 (diff)
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
-rwxr-xr-xscripts/jogamp-log02.sh1
-rwxr-xr-xscripts/start.jabot.sh1
-rw-r--r--src/org/jogamp/jabot/irc/CatOut.java112
-rw-r--r--src/org/jogamp/jabot/irc/LogBot.java32
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<args.length; i++) {
- if(args[i].equals("-login")) {
+ if(args[i].equals("-joinMessage")) {
+ i++;
+ _joinMessage = args[i];
+ } else if(args[i].equals("-login")) {
i++;
_login = args[i];
} else if(args[i].equals("-name")) {
@@ -83,6 +87,9 @@ public class CatOut extends PircBot {
} else if(args[i].equals("-logprefix")) {
i++;
_logprefix = args[i];
+ } else if(args[i].equals("-urlprefix")) {
+ i++;
+ _urlprefix = args[i];
} else if(args[i].equals("-logrotateStart")) {
i++;
final String hhmmS = args[i];
@@ -103,15 +110,17 @@ public class CatOut extends PircBot {
null == _server ||
null == _channelNoHash ||
( _htmlOut && null == _htmlHeader || null == _htmlFooter ) ) {
- System.err.println("Incomplete commandline, use "+CatOut.class.getName()+" -login VAL -name VAL -server VAL -channel VAL [-verbose] [-htmlHeader VAL -htmlFooter VAL] [-logrotate millis [-logrotateStart hhmm] [-logprefix VAL]");
+ System.err.println("Incomplete commandline, use "+CatOut.class.getName()+" -login VAL -name VAL -server VAL -channel VAL [-verbose] [-joinMessage VAL] [-htmlHeader VAL -htmlFooter VAL] [-logrotate millis [-logrotateStart hhmm] [-logprefix VAL] [-urlprefix VAL]]");
return;
}
+ joinMessage = _joinMessage;
login=_login; name=_name;
server=_server; channelNoHash=_channelNoHash;
verbose=_verbose;
logrotate = _logrotate;
logrotateStart = _logrotateStart;
logprefix = _logprefix;
+ urlprefix = _urlprefix;
htmlOut = _htmlOut;
htmlHeader = new File(_htmlHeader);
htmlFooter= new File(_htmlFooter);
@@ -136,12 +145,14 @@ public class CatOut extends PircBot {
final LogBot bot = new LogBot(showHostname, joinMessage, htmlOut);
bot.setVerbose(verbose);
bot.setLoginAndName(login, name);
- PrintStream fout;
+ LogStream logOut;
if ( 0 < logrotate ) {
- fout = createLogStream(bot, logprefix, server, channelNoHash, htmlHeader);
- bot.setOut(fout, true);
+ logOut = new LogStream(bot, logprefix, urlprefix, server, channelNoHash, htmlHeader);
+ bot.setOut(logOut.out, true);
+ bot.setJoinMessage(joinMessage+" @ "+logOut.urlString);
+ bot.logNotice(bot.getJoinMessage());
} else {
- fout = null;
+ logOut = null;
}
bot.connect(server);
bot.joinChannel(HASH+channelNoHash);
@@ -151,13 +162,16 @@ public class CatOut extends PircBot {
if( now >= 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("<h2>"+head+"</h2>");
+ out.println("<br/>");
+ out.flush();
}
- out.flush();
- input.close();
- }
- public static void htmlHead(String head, PrintStream out) {
- out.println("<h2>"+head+"</h2>");
- out.println("<br/>");
- 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);
}
}