You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ch...@apache.org on 2013/02/21 22:02:23 UTC
svn commit: r1448800 - in /uima/sandbox/uima-ducc/trunk:
uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ConsoleListener.java
uima-ducc-spawn/src/ducc_ling.c
Author: challngr
Date: Thu Feb 21 21:02:22 2013
New Revision: 1448800
URL: http://svn.apache.org/r1448800
Log:
UIMA-2644
ducc_ling sends log file name in a line tagged thus:
1002 CONSOLE_REDIRECT fn
where fn is the file name. Listeners can extract the fn and tee the
log to a file and stdout. The update to ConsoleListener does just this.
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ConsoleListener.java
uima/sandbox/uima-ducc/trunk/uima-ducc-spawn/src/ducc_ling.c
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ConsoleListener.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ConsoleListener.java?rev=1448800&r1=1448799&r2=1448800&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ConsoleListener.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-cli/src/main/java/org/apache/uima/ducc/cli/ConsoleListener.java Thu Feb 21 21:02:22 2013
@@ -19,6 +19,8 @@
*/
package org.apache.uima.ducc.cli;
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
@@ -151,6 +153,12 @@ class ConsoleListener
String remote_host;
String leader;
+ BufferedOutputStream logfile = null;
+ String filename = null;
+ static final String console_tag = "1002 CONSOLE_REDIRECT ";
+ int tag_len = 0;
+ boolean first_error = true;
+
StdioListener(Socket sock, ConsoleListener cl)
{
this.sock = sock;
@@ -165,6 +173,7 @@ class ConsoleListener
remote_host = remote_host.substring(0, ndx);
}
leader = "[" + remote_host + "] ";
+ tag_len = console_tag.length();
}
public void close()
@@ -174,6 +183,37 @@ class ConsoleListener
this.done = true;
is.close();
cl.delete(sock.getPort());
+
+ logfile.flush();
+ logfile.close();
+ }
+
+ void tee(String leader, String line)
+ {
+ try {
+ if ((logfile == null) && line.startsWith(console_tag)) {
+ filename = line.substring(tag_len);
+ logfile = new BufferedOutputStream(new FileOutputStream(filename));
+
+ System.out.println("Create logfile " + filename);
+ }
+ if (logfile != null) {
+ logfile.write(leader.getBytes());
+ logfile.write(' ');
+ logfile.write(line.getBytes());
+ logfile.write('\n');
+ logfile.flush();
+ } else {
+ System.out.println("Bypass logfile");
+ }
+ } catch (Exception e) {
+ if ( first_error ) {
+ System.out.println("Cannot create or write log file[" + filename + "]: " + e.getMessage());
+ e.printStackTrace();
+ }
+ first_error = false;
+ }
+ System.out.println(leader + line);
}
/**
@@ -195,7 +235,7 @@ class ConsoleListener
if ( len < 0 ) {
// this is a lone linend. Spew the partial if it exists and just return.
if ( partial != null ) {
- System.out.println(leader + partial);
+ tee(leader, partial);
partial = null;
}
return;
@@ -210,12 +250,12 @@ class ConsoleListener
for ( int i = 0; i < len; i++ ) {
// spew everything but the last line
- System.out.println(leader + lines[i]);
+ tee(leader, lines[i]);
}
if ( tmp.endsWith("\n") ) {
// if the last line ends with linend, there is no partial, just spew
- System.out.println(leader + lines[len]);
+ tee(leader, lines[len]);
partial = null;
} else {
// otherwise, wait for the next buffer
Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-spawn/src/ducc_ling.c
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-spawn/src/ducc_ling.c?rev=1448800&r1=1448799&r2=1448800&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-spawn/src/ducc_ling.c (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-spawn/src/ducc_ling.c Thu Feb 21 21:02:22 2013
@@ -468,6 +468,7 @@ int main(int argc, char **argv, char **e
char *userid = NULL;
char *filepath = NULL;
char *workingdir = NULL;
+ char *logfile = NULL;
struct passwd *pwd= NULL;
int switch_ids = 0;
int redirect = 0;
@@ -508,17 +509,18 @@ int main(int argc, char **argv, char **e
exit(1);
}
- if ( filepath != NULL ) {
- fprintf(stdout, "301 Redirecting console into file %s.\n", filepath);
- redirect = 1;
- }
if ( getenv("DUCC_CONSOLE_LISTENER") != NULL ) {
fprintf(stdout, "302 Redirecting console into socket %s.\n", getenv("DUCC_CONSOLE_LISTENER"));
redirect = 1;
+ } else if ( filepath != NULL ) {
+ fprintf(stdout, "301 Redirecting console into file %s.\n", filepath);
+ redirect = 1;
}
- if ( ! redirect ) {
+ if ( redirect ) {
+ logfile = mklogfile(filepath);
+ } else {
fprintf(stdout, "300 Bypassing redirect of log.\n");
}
@@ -607,6 +609,10 @@ int main(int argc, char **argv, char **e
char *console_port = getenv("DUCC_CONSOLE_LISTENER");
if ( console_port != NULL ) {
redirect_to_socket(console_port);
+ if ( filepath != NULL ) {
+ // on console redirection, spit out the name of the log file it would have been
+ fprintf(stdout, "1002 CONSOLE_REDIRECT %s\n", logfile);
+ }
} else {
redirect_to_file(filepath);
}