verbose logging

41 views
Skip to first unread message

Lee Henson

unread,
Jul 6, 2011, 7:04:57 AM7/6/11
to Rails Trinidad
Hi

Is there an easy way to turn off the log line and new line which
precedes every log message sent out from rails logger?

e.g. instead of:

Jul 6, 2011 11:58:33 AM org.apache.catalina.core.ApplicationContext
log
INFO: 11:58:33 action_controller Processing by
User::DashboardController#show as HTML

Jul 6, 2011 11:58:33 AM org.apache.catalina.core.ApplicationContext
log
INFO: 11:58:33 action_view Rendered layouts/authenticated/
_context.html.haml (33.0ms)

Jul 6, 2011 11:58:34 AM org.apache.catalina.core.ApplicationContext
log
INFO: 11:58:34 action_view Rendered app/cells/primary_menu/
show.html.haml (159.0ms)

...this would be nicer....

INFO: 11:58:33 action_controller Processing by
User::DashboardController#show as HTML
INFO: 11:58:33 action_view Rendered layouts/authenticated/
_context.html.haml (33.0ms)
INFO: 11:58:34 action_view Rendered app/cells/primary_menu/
show.html.haml (159.0ms)

?

I've tried "trinidad | grep -v apache" but that doesn't make any
difference so perhaps you can't pipe the log output in that way.

Cheers!

David Calavera

unread,
Jul 6, 2011, 10:49:18 AM7/6/11
to rails-t...@googlegroups.com
Hi Lee,

the short answer to that question is "yes and no" :P

Some time ago I wrote an extension that allowed to modify the log format using log4j, I think that would be the easier solution to your issue:


The solution slightly harder, but not too much, would be to modify the log formatter that Trinidad uses by default. I've heard other people complaining about this, so maybe we need to go with this solution.

This is where we set the default log formatter:


We can create a custom formatter, internet is full of examples.

If you are willing to go with this solution I'd be really glad to help you if you want to send a patch.


--
Has recibido este mensaje porque estás suscrito al grupo "Rails Trinidad" de Grupos de Google.
Para publicar una entrada en este grupo, envía un correo electrónico a rails-t...@googlegroups.com.
Para anular tu suscripción a este grupo, envía un correo electrónico a rails-trinida...@googlegroups.com
Para tener acceso a más opciones, visita el grupo en http://groups.google.com/group/rails-trinidad?hl=es.


Lee Henson

unread,
Jul 7, 2011, 7:03:52 AM7/7/11
to Rails Trinidad
Hi David

I've forked and added a "formatter" branch:

https://github.com/leemhenson/trinidad/tree/formatter

I've created a new jar containing a single class:

=========== TerseFormatter.java =============
package org.trinidad.logging;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class TerseFormatter extends Formatter {
private static final DateFormat format = new SimpleDateFormat("yyyy-
MM-dd HH:mm:ss");

@Override
public String format(LogRecord record) {
StringBuffer sb = new StringBuffer();

sb.append(format.format(new Date(record.getMillis())));
sb.append(" ");
sb.append(record.getLevel().getName());
sb.append(": ");
sb.append(record.getMessage());

return sb.toString();
}
}
========================================

Unfortunately it is being ignored by logging system. There aren't any
errors being generated when I run "rake spec", but the log messages
are still the same old format.

1) Any ideas? I believe the old call to "log_handler.formatter =
SimpleFormatter.new" was silently being ignored as well. You can even
comment that line out entirely and the behaviour is unchanged. From
looking at LogManager there appears to be some sort of configuration
you can do from an xml file, or java properties. I'm not experienced
with java so this is all a bit impenetrable to me at the moment.

2) Where would you like me to put the TerseFormatter.java in git?

cheers
lee

On Jul 6, 3:49 pm, David Calavera <david.calav...@gmail.com> wrote:
> Hi Lee,
>
> the short answer to that question is "yes and no" :P
>
> Some time ago I wrote an extension that allowed to modify the log format
> using log4j, I think that would be the easier solution to your issue:
>
> https://github.com/calavera/trinidad_logging_extension
>
> The solution slightly harder, but not too much, would be to modify the log
> formatter that Trinidad uses by default. I've heard other people complaining
> about this, so maybe we need to go with this solution.
>
> This is where we set the default log formatter:
>
> https://github.com/trinidad/trinidad/blob/master/lib/trinidad/lifecyc...

David Calavera

unread,
Jul 7, 2011, 7:25:15 AM7/7/11
to rails-t...@googlegroups.com
That's pretty cool Lee!!!

I'm sending this from the iphone, but I'll try to guide you.

The formatter is being ignored because you added only for the file logger. Do you see a loop up in that code that says something like:

logger.handlers.each |handler|
...

You have to add the formatter to those handlers too, there should be just one, the ConsoleHandler.

On the other hand, java?? really?? :P Could you implement it with ruby? So we don't need to compile the code and things like that. Let me help you to start:

module Trinidad
java_import ...
java_import ...

class TerseFormatter < Formatter
def format(record)
...
end
end
end

Thank you!!!

Reply all
Reply to author
Forward
0 new messages