summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-01-19 08:49:32 +0100
committerSven Gothel <[email protected]>2013-01-19 08:49:32 +0100
commit60ccfc5ff7dee58740ba1302626e3ccea35259b9 (patch)
tree326619264a1b24d8c21332b4deae98127dc24ec4
parent6b370c09e17285d703e805a6fbfbc341d5ec1b60 (diff)
Add id/href to each line enabling linking to each message; Simplify loop; Set logstream before start; Add logrotateStart time.
-rwxr-xr-xassets/style.css2
-rwxr-xr-xscripts/jogamp-log02.sh5
-rwxr-xr-xscripts/start.jabot.sh1
-rw-r--r--src/org/jogamp/jabot/irc/CatOut.java115
-rw-r--r--src/org/jogamp/jabot/irc/LogBot.java19
5 files changed, 98 insertions, 44 deletions
diff --git a/assets/style.css b/assets/style.css
index fe3f3e0..144f79e 100755
--- a/assets/style.css
+++ b/assets/style.css
@@ -32,6 +32,8 @@ body {padding:15px 20px; margin:0; background: #f5f5f5; font-family: "Trebuchet
.clear {clear: both}
.column {float: left; padding-left: 25px; padding-right: 50px}
+.irc-date a {color:#111111; background-color: #f5f5f5; border-style:none; text-decoration:none;}
+.irc-date a:hover {color:#000000; background-color: #eeeeee; border-style:none; text-decoration:underline;}
.irc-date {font-family: Courier New, Courier, mono;}
.irc-green {color: #009200;}
.irc-black {color: #000000;}
diff --git a/scripts/jogamp-log02.sh b/scripts/jogamp-log02.sh
index 8d01afb..42a6c2d 100755
--- a/scripts/jogamp-log02.sh
+++ b/scripts/jogamp-log02.sh
@@ -3,9 +3,10 @@
LOGFILE=irc_jogamp_CatOut_slog_`date -u +%Y%m%d%H%M`.log
java -cp build/jabot.jar org.jogamp.jabot.irc.CatOut \
- -login jogamp -name CatOut \
+ -login jogamp2 -name CatOut2 \
-server irc.freenode.net -channel jogamp \
- -logrotate 10000 \
+ -logrotate 60000 \
+ -logrotateStart 0736 \
-logprefix "log/irc/" \
-htmlHeader assets/header.html \
-htmlFooter assets/footer.html \
diff --git a/scripts/start.jabot.sh b/scripts/start.jabot.sh
index 1e332ee..46a9bd6 100755
--- a/scripts/start.jabot.sh
+++ b/scripts/start.jabot.sh
@@ -9,6 +9,7 @@ nohup nice $JAVA \
-login jogamp -name CatOut \
-server irc.freenode.net -channel jogamp \
-logrotate 86400000 \
+ -logrotateStart 0505 \
-logprefix "/home/jogl/jogamp.org/log/irc/" \
-htmlHeader $JABOT_HOME/assets/header.html \
-htmlFooter $JABOT_HOME/assets/footer.html \
diff --git a/src/org/jogamp/jabot/irc/CatOut.java b/src/org/jogamp/jabot/irc/CatOut.java
index bb53211..f6812af 100644
--- a/src/org/jogamp/jabot/irc/CatOut.java
+++ b/src/org/jogamp/jabot/irc/CatOut.java
@@ -16,6 +16,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Locale;
import org.jibble.pircbot.PircBot;
import org.jogamp.jabot.util.TimeTool;
@@ -38,14 +40,14 @@ public class CatOut extends PircBot {
final boolean showHostname = false;
final String login, name, server, channelNoHash;
final boolean verbose;
- final long logrotate;
+ final long logrotate, logrotateStart;
final String logprefix;
final boolean htmlOut;
final File htmlHeader, htmlFooter;
{
String _login=null, _name=null, _server=null, _channelNoHash=null;
boolean _verbose=false;
- long _logrotate = 0;
+ long _logrotate = 0, _logrotateStart=System.currentTimeMillis();
String _logprefix="";
boolean _htmlOut = false;
String _htmlHeader = null, _htmlFooter=null;
@@ -81,6 +83,19 @@ public class CatOut extends PircBot {
} else if(args[i].equals("-logprefix")) {
i++;
_logprefix = args[i];
+ } else if(args[i].equals("-logrotateStart")) {
+ i++;
+ final String hhmmS = args[i];
+ if( 4 == hhmmS.length() ) {
+ final String hhS = hhmmS.substring(0, 2);
+ final String mmS = hhmmS.substring(2, 4);
+ final int hh = (int)atol(hhS, 0);
+ final int mm = (int)atol(mmS, 0);
+ final Calendar cal = new GregorianCalendar(TimeTool.getNearZuluTimeZone(), Locale.getDefault());
+ cal.set(Calendar.HOUR, hh);
+ cal.set(Calendar.MINUTE, mm);
+ _logrotateStart = cal.getTimeInMillis();
+ }
}
}
if( null == _login ||
@@ -88,72 +103,91 @@ 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 [-logprefix VAL]]");
+ 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]");
return;
}
login=_login; name=_name;
server=_server; channelNoHash=_channelNoHash;
verbose=_verbose;
logrotate = _logrotate;
+ logrotateStart = _logrotateStart;
logprefix = _logprefix;
htmlOut = _htmlOut;
htmlHeader = new File(_htmlHeader);
htmlFooter= new File(_htmlFooter);
}
+ long nextLogrotate = logrotateStart + logrotate;
+ final Calendar logCal = new GregorianCalendar(TimeTool.getNearZuluTimeZone(), Locale.getDefault());
+ if(0 < logrotate) {
+ if( System.currentTimeMillis() > nextLogrotate ) {
+ nextLogrotate += logrotate;
+ }
+ System.err.println("Now : "+logCal.getTime());
+ logCal.setTimeInMillis(logrotateStart);
+ System.err.println("Logrotate Start : "+logCal.getTime());
+ logCal.setTimeInMillis(logrotate);
+ System.err.println("Logrotate Period: "+logCal.getTime()+", "+logrotate+" ms");
+ logCal.setTimeInMillis(nextLogrotate);
+ System.err.println("Next Logrotate-1: "+logCal.getTime());
+ logCal.setTimeInMillis(nextLogrotate+logrotate);
+ System.err.println("Next Logrotate-2: "+logCal.getTime());
+ }
final LogBot bot = new LogBot(showHostname, joinMessage, htmlOut);
bot.setVerbose(verbose);
bot.setLoginAndName(login, name);
+ PrintStream fout;
+ if ( 0 < logrotate ) {
+ fout = createLogStream(bot, logprefix, server, channelNoHash, htmlHeader);
+ bot.setOut(fout, true);
+ } else {
+ fout = null;
+ }
bot.connect(server);
bot.joinChannel(HASH+channelNoHash);
- if( 0 >= logrotate ) {
- // bot.sendRawLine("NAMES "+HASH+channelNoHash); // FIXME ?
- } else {
- PrintStream fout = null;
- long t0 = System.currentTimeMillis();
- int sendNamesCount = 0;
+ if( 0 < logrotate ) {
while(true) { // forever !
- // Swap Logfiles: Open and set new logfile, then close old one.
- {
- final Calendar calendar = bot.tick();
- final String suffix = htmlOut ? ".html" : ".txt" ;
- final String logfilename = logprefix+channelNoHash+"_"+TimeTool.getTimeStamp(calendar, true, false)+suffix;
- final File _file = new File(logfilename);
- final PrintStream _fout = new PrintStream(new FileOutputStream(_file));
+ final long now = System.currentTimeMillis();
+
+ 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);
if(htmlOut) {
- cat(htmlHeader, _fout);
- htmlHead(HASH+channelNoHash+" @ "+server+" - "+bot.getTimeStamp()+" ("+calendar.getTimeZone().getID()+")",
- _fout);
- }
- bot.setOut(_fout);
- // bot.sendRawLine("NAMES "+HASH+channelNoHash); // FIXME ?
- if(null != fout) {
- if(htmlOut) {
- cat(htmlFooter, fout);
- }
- fout.close(); // implies flush
+ cat(htmlFooter, fout);
}
+ fout.close(); // implies flush
fout = _fout;
+ nextLogrotate += logrotate;
+ logCal.setTimeInMillis(now);
+ System.err.println("Now : "+logCal.getTime());
+ logCal.setTimeInMillis(nextLogrotate);
+ System.err.println("Next Logrotate: "+logCal.getTime());
}
- final long t1 = System.currentTimeMillis();
- long td = 0;
- while ( td < logrotate ) {
- try {
- Thread.sleep(FLUSH_INTERVAL);
- } catch (Exception e) { }
+ try {
+ Thread.sleep(FLUSH_INTERVAL);
+ } catch (Exception e) { }
+ if(null != fout) {
fout.flush();
- final long t2 = System.currentTimeMillis();
- td = t2 - t1;
- if ( sendNamesCount < ( t2 - t0 ) / SEND_NAMES ) {
- // bot.sendRawLine("NAMES "+HASH+channelNoHash); // FIXME ?
- sendNamesCount++;
- }
}
}
}
}
public static final long FLUSH_INTERVAL = 60*1000; // flush every minute
- public static final long SEND_NAMES = 10*60*1000; // every 10 minutes
+
+ 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);
+ }
+ return _fout;
+ }
public static void cat(File source, PrintStream out) throws IOException {
final BufferedInputStream input = new BufferedInputStream(new FileInputStream(source));
@@ -168,5 +202,6 @@ public class CatOut extends PircBot {
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 e334ae8..9c085a2 100644
--- a/src/org/jogamp/jabot/irc/LogBot.java
+++ b/src/org/jogamp/jabot/irc/LogBot.java
@@ -43,6 +43,7 @@ public class LogBot extends PircBot {
private final boolean xmlOut;
private final Object outSync = new Object();
private PrintStream out;
+ private int lineCount;
public LogBot(boolean showHostname, String joinMessage, boolean xmlOut) {
this(showHostname, joinMessage, TimeTool.getNearZuluTimeZone(), Locale.getDefault(), System.out, xmlOut);
@@ -54,6 +55,7 @@ public class LogBot extends PircBot {
this.xmlOut = xmlOut;
this.out = out;
this.joinMessage = joinMessage;
+ this.lineCount = 0;
}
public final void setLoginAndName(String login, String nick) {
@@ -93,16 +95,28 @@ public class LogBot extends PircBot {
return out;
}
}
- public PrintStream setOut(PrintStream newOut) {
+ public PrintStream setOut(PrintStream newOut, boolean resetLineCount) {
synchronized(outSync) {
final PrintStream old = out;
out = newOut;
+ if( resetLineCount ) {
+ lineCount = 0;
+ }
return old;
}
}
+ public int getLineCount() {
+ return lineCount;
+ }
+ public void resetLineCount() {
+ synchronized(outSync) {
+ lineCount = 0;
+ }
+ }
public void append(String color, String line) {
tick();
+ lineCount++;
if(xmlOut) {
line = Colors.removeFormattingAndColors(line);
@@ -117,7 +131,8 @@ public class LogBot extends PircBot {
synchronized(outSync) {
if(xmlOut) {
- out.println("<span class=\"irc-date\">[" + getTimeStamp() + "]</span> <span class=\"" + color + "\">" + line + "</span><br />");
+ // <span class="irc-date" id="l232"><a href="#l232">20130117 21:06:04</a></span>
+ out.println("<span class=\"irc-date\" id=\"l"+lineCount+"\"><a href=\"#l"+lineCount+"\">" + getTimeStamp() + "</a></span> <span class=\"" + color + "\">" + line + "</span><br />");
} else {
out.println(getTimeStamp()+" "+line);
}