logback database appender

View: New views
2 Messages — Rating Filter:   Alert me  

logback database appender

by nknk :: Rate this Message:

| View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Quick question – does logback database appender work only with the 3 pre-defined tables?

I would like to log to my own tables that have different structure.  Is it possible to do?

 

Thanks so much!

 

Nadia

 


_______________________________________________
Logback-user mailing list
Logback-user@...
http://mailman.qos.ch/mailman/listinfo/logback-user

Re: logback database appender

by Pepe Caballero :: Rate this Message:

| View Threaded | Show Only this Message

you can extend DBNameResolver something like

public class MyDBNameResolver  implements DBNameResolver{
    private String tableNamePrefix = "MYTABLE_";

             private String tableNameSuffix = "";
             public static final String SELECT_CURRVAL = "SELECT MYTABLE_event_id_seq.currval from dual";
             public <N extends Enum<?>> String getTableName(N tableName) {
             
                    if(tableName.name().toLowerCase().equals("logging_event"))
                        return tableNamePrefix + "event" + tableNameSuffix;
                    if(tableName.name().toLowerCase().equals("logging_event_property"))
                        return tableNamePrefix + "event_property" + tableNameSuffix;
                    if(tableName.name().toLowerCase().equals("logging_event_exception"))
                        return tableNamePrefix + "event_exception" + tableNameSuffix;
                       
                        throw new IllegalArgumentException(tableName + " is an unknown table name");
           
             }

             

             
             public <N extends Enum<?>> String getColumnName(N columnName) {
                     
                     return columnName.name().toLowerCase() ;          
             }

             public void setTableNamePrefix(String tableNamePrefix) {
               this.tableNamePrefix = tableNamePrefix != null? tableNamePrefix : "";
             }

             public void setTableNameSuffix(String tableNameSuffix) {
               this.tableNameSuffix = tableNameSuffix != null? tableNameSuffix : "";
             }
}


and in logback.xml you use it

  <dbNameResolver class="MyDBNameResolver"/>

nknk wrote:
Quick question - does logback database appender work only with the 3 pre-defined tables?
I would like to log to my own tables that have different structure.  Is it possible to do?

Thanks so much!

Nadia


_______________________________________________
Logback-user mailing list
Logback-user@qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-user