You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Meera Mehta <me...@yahoo.com> on 2006/04/19 08:45:43 UTC

Custom Level-How to assign priority dynamically.

Hi,
In my application i want custom level SQL(which logs
all SQL statements.

I have one flag isSQLEnable which is controlling
behaviour of SQL statement logging.

When flag is On:
Priority of rootLogger is 
either (1)SQL  OR  (2) DEBUG(or any other valid Level)

1) when Priority is SQL i want to generate Warning
plus SQL logs (SQL statements only).

2) When priority is DEBUG
I want to generate All logs plus SQL logs.

When flag is OFF:

Priority of rootLogger is 
either (1)SQL  OR  (2) DEBUG(or any other valid Level)

1) when priority of rootLogger is SQL
I want warning and Empty log file(all msgs should be
discarded).
2) priority of rootLogger is say DEBUG
I want Normal logs according to priority without SQL
logs(because flag is OFF).

I have my custom level and property configurator
class.

My question is that am i on right track or is there
any better way to do this?????

If i am right then how can i dynamically assign
priority to SQL level??

please guide me.


Note:
isSQLEnable is my custom key which i have added, for
that i have extended PropertyConfigurator class.
I am using log4j.properties as config file.
I am also using commons loggin.
I dont have code level access to any of my client
class.

thanks 
Meera


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Custom Level-How to assign priority dynamically.

Posted by Curt Arnold <ca...@apache.org>.
On Apr 19, 2006, at 11:03 PM, Meera Mehta wrote:

> Thanks for reply James.
>
> Let me make you more clear.
>
> I want Separate Level SQL and i want to enable/disable
> it with Flag(isSQLEnable),regardless of current
> Priority.
>
> I dont have any code level access to my
> application.(As i mensioned we are using commons
> logging extension)so i can not create separate logger
> in the code.
>
> if i create separate logger in properties file with
> name say
>
> log4j.logger.SQL=SQL,<Appender list...>
> ..........
>
> will it log request(with SQL Level)coming from any
> package(say my package is com.app.test will it accepts
> SQL log request generated from this package also)??
>
> Hope so i am able to make you more clear!!!
> Thanks in advance.


First, let me reemphasize what others have said:  you are trying to  
make Level do what Logger is designed to do and does well.  The idea  
behind a hierarchy of loggers is to allow you to organize messages by  
a topic (usually the class where the logging request originated) and  
then control the processing of those messages.  Since almost all the  
examples use class names for logger (topic) names, many people assume  
that logger names must be class names.

You state that "you do not have code level access".  If you aren't  
able to change the code, how would you add logging requests that used  
your proposed new level?  If you can write new logging calls, then  
you can introduce new loggers.

As a start, I'd suggest something along the line of:

public class SomeClass {
      //
      //   standard diagnostic logger
      private static final Logger logger = Logger.getLogger 
(SomeClass.class);
      //
      //  a distinct logger for database related logging (could be  
just called sql or "sql." + class name
      private static final Logger sqlLogger = Logger.getLogger 
("sql.com.example.myapp.SomeClass");

      public void store() {
           logger.debug("storing instance to database");
           sqlLogger.info(sqlStatement);
      }
}

If you wanted to turn off all loggers that start with "sql.", then  
you could execute:

Logger.getLogger("sql").setLevel(Level.OFF);





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Custom Level-How to assign priority dynamically.

Posted by Meera Mehta <me...@yahoo.com>.
Thanks for reply James.

Let me make you more clear.

I want Separate Level SQL and i want to enable/disable
it with Flag(isSQLEnable),regardless of current
Priority.

I dont have any code level access to my
application.(As i mensioned we are using commons
logging extension)so i can not create separate logger
in the code.

if i create separate logger in properties file with
name say 

log4j.logger.SQL=SQL,<Appender list...>
..........

will it log request(with SQL Level)coming from any
package(say my package is com.app.test will it accepts
SQL log request generated from this package also)??

Hope so i am able to make you more clear!!!
Thanks in advance.

--- James Stauffer <st...@gmail.com> wrote:

> I don't quite understand what you are trying to do
> but it appears that
> you don't want the SQL level to be in the same
> ordering as the other
> levels.
> Would it work to just send all SQL logs to a
> separate logger?  Then
> you could turn them on or off separately from the
> level of the rest of
> the logs.
> 
> On 4/19/06, Meera Mehta <me...@yahoo.com>
> wrote:
> > Hi,
> > In my application i want custom level SQL(which
> logs
> > all SQL statements.
> >
> > I have one flag isSQLEnable which is controlling
> > behaviour of SQL statement logging.
> >
> > When flag is On:
> > Priority of rootLogger is
> > either (1)SQL  OR  (2) DEBUG(or any other valid
> Level)
> >
> > 1) when Priority is SQL i want to generate Warning
> > plus SQL logs (SQL statements only).
> >
> > 2) When priority is DEBUG
> > I want to generate All logs plus SQL logs.
> >
> > When flag is OFF:
> >
> > Priority of rootLogger is
> > either (1)SQL  OR  (2) DEBUG(or any other valid
> Level)
> >
> > 1) when priority of rootLogger is SQL
> > I want warning and Empty log file(all msgs should
> be
> > discarded).
> > 2) priority of rootLogger is say DEBUG
> > I want Normal logs according to priority without
> SQL
> > logs(because flag is OFF).
> >
> > I have my custom level and property configurator
> > class.
> >
> > My question is that am i on right track or is
> there
> > any better way to do this?????
> >
> > If i am right then how can i dynamically assign
> > priority to SQL level??
> >
> > please guide me.
> >
> >
> > Note:
> > isSQLEnable is my custom key which i have added,
> for
> > that i have extended PropertyConfigurator class.
> > I am using log4j.properties as config file.
> > I am also using commons loggin.
> > I dont have code level access to any of my client
> > class.
> >
> > thanks
> > Meera
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail:
> log4j-user-help@logging.apache.org
> >
> >
> 
> 
> --
> James Stauffer
> Are you good? Take the test at
> http://www.livingwaters.com/good/
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail:
> log4j-user-help@logging.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Custom Level-How to assign priority dynamically.

Posted by James Stauffer <st...@gmail.com>.
I don't quite understand what you are trying to do but it appears that
you don't want the SQL level to be in the same ordering as the other
levels.
Would it work to just send all SQL logs to a separate logger?  Then
you could turn them on or off separately from the level of the rest of
the logs.

On 4/19/06, Meera Mehta <me...@yahoo.com> wrote:
> Hi,
> In my application i want custom level SQL(which logs
> all SQL statements.
>
> I have one flag isSQLEnable which is controlling
> behaviour of SQL statement logging.
>
> When flag is On:
> Priority of rootLogger is
> either (1)SQL  OR  (2) DEBUG(or any other valid Level)
>
> 1) when Priority is SQL i want to generate Warning
> plus SQL logs (SQL statements only).
>
> 2) When priority is DEBUG
> I want to generate All logs plus SQL logs.
>
> When flag is OFF:
>
> Priority of rootLogger is
> either (1)SQL  OR  (2) DEBUG(or any other valid Level)
>
> 1) when priority of rootLogger is SQL
> I want warning and Empty log file(all msgs should be
> discarded).
> 2) priority of rootLogger is say DEBUG
> I want Normal logs according to priority without SQL
> logs(because flag is OFF).
>
> I have my custom level and property configurator
> class.
>
> My question is that am i on right track or is there
> any better way to do this?????
>
> If i am right then how can i dynamically assign
> priority to SQL level??
>
> please guide me.
>
>
> Note:
> isSQLEnable is my custom key which i have added, for
> that i have extended PropertyConfigurator class.
> I am using log4j.properties as config file.
> I am also using commons loggin.
> I dont have code level access to any of my client
> class.
>
> thanks
> Meera
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


--
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org