Re: Newlines in error_log

Shugo Maeda <[email protected]> Sat, 26 Jun 2004 00:13:20 +0900
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>

Hi,

> I've got a little problem with the error reporting of mod-ruby. It was 
> working correctly before, but I upgraded to apache and mod-ruby, and now 
> my error messages are all appearing on one line like so:

Can you try this patch?

Shugo




--- ../mod-ruby-1.2.0/mod_ruby.c	2004-04-30 14:44:18.000000000 +0900
+++ mod_ruby.c	2004-06-26 00:06:09.000000000 +0900
@@ -392,13 +392,13 @@
 	len = ep->len;
 	for (i=1; i<len; i++) {
 	    if (TYPE(ep->ptr[i]) == T_STRING) {
-		STR_CAT_LITERAL(str, "\tfrom ");
+		STR_CAT_LITERAL(str, "  from ");
 		rb_str_cat(str, RSTRING(ep->ptr[i])->ptr, RSTRING(ep->ptr[i])->len);
 		STR_CAT_LITERAL(str, "\n");
 	    }
 	    if (i == TRACE_HEAD && len > TRACE_MAX) {
 		char buff[BUFSIZ];
-		snprintf(buff, BUFSIZ, "\t ... %ld levels...\n",
+		snprintf(buff, BUFSIZ, "   ... %ld levels...\n",
 			 len - TRACE_HEAD - TRACE_TAIL);
 		rb_str_cat(str, buff, strlen(buff));
 		i = len - TRACE_TAIL;
@@ -449,7 +449,7 @@
 }
 
 void ruby_log_error(const char *file, int line, int level,
-			const server_rec *s, const char *fmt, ...)
+                    const server_rec *s, const char *fmt, ...)
 {
     va_list args;
     char buf[BUFSIZ];
@@ -466,12 +466,15 @@
 
 void ruby_log_error_string(server_rec *s, VALUE errmsg)
 {
-    VALUE logmsg;
+    VALUE msgs;
+    int i;
 
-    logmsg = STRING_LITERAL("error in ruby\n");
-    rb_str_concat(logmsg, errmsg);
-    ruby_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, s,
-		   "%s", StringValuePtr(logmsg));
+    ruby_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, s, "error in ruby");
+    msgs = rb_str_split(errmsg, "\n");
+    for (i = 0; i < RARRAY(msgs)->len; i++) {
+        ruby_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, s,
+                       "%s", StringValuePtr(RARRAY(msgs)->ptr[i]));
+    }
 }
 
 static void handle_error(request_rec *r, int state)
@@ -544,6 +547,9 @@
 static int ruby_startup(pool *p, pool *plog, pool *ptemp, server_rec *s)
 {
     ap_add_version_component(p, MOD_RUBY_STRING_VERSION);
+#if RUBY_RELEASE_CODE > 20040624
+    ap_add_version_component(p, apr_pstrcat(p, "Ruby/", ruby_version, NULL));
+#endif
     return OK;
 }
 
@@ -552,6 +558,9 @@
 static void ruby_startup(server_rec *s, pool *p)
 {
     ap_add_version_component(MOD_RUBY_STRING_VERSION);
+#if RUBY_RELEASE_CODE > 20040624
+    ap_add_version_component(ap_pstrcat(p, "Ruby/", ruby_version, NULL));
+#endif
 }
 
 #endif