Sharing Appenders between loggers?

2010-03-18 Thread Tasso Angelidis
log4j.rootLogger = ERROR, stdout
log4j.logger.org.jboss = DEBUG, A1
log4j.logger.ca.xyz = INFO, A1

A1 is a DaylyRollingFileAppender. Just wondering of both logers can use the 
same A1 appender.

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



Question about file locking

2010-03-17 Thread Tasso Angelidis
I'm using log4j in a pretty vanilla way... No extra applications logging to the 
same file... 1 logger per class. Using RollingFileAppender...

Is the file exclusively locked or share locked?

And for Windows we all know that sometimes a file can remain locked after 
unexpected program termination how is this dealt with?

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



RE: Understanding log levels

2008-05-15 Thread Tasso Angelidis
The only problem I have now is that pre-pending operations I canot fully use 
hiarchy of loggers.

Bassically I wrote a quartz application that schedules various jobs. So I want 
to keep the logs of the application separate from the logs of the jobs. Jobs 
consist of a quartz job and as well any supporting classes required. So I 
further grouped the jobs.

logger name=operations.com.rbs
appender-ref ref=ops/
/logger   

logger name=com.pt.jobs.SFTPUpload additivity=false -- Do not 
use the root
appender-ref ref=SFTPUpload/
appender-ref ref=SFTPError/
/logger   

logger name=operations.pt.rbs.jobs.SFTPUpload additivity=false 
-- Problem with this is I have to repeat the appender refs. Unless I post fix 
operations, which then means I have to have separate loggers for each class 
under SFTUpload.
appender-ref ref=SFTPUpload/
appender-ref ref=SFTPError/
appender-ref ref=ops/
/logger   


root
level value=info /
appender-ref ref=log/
appender-ref ref=error/
/root 

-Original Message-
From: Curt Arnold [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 08, 2008 1:56 PM
To: Log4J Users List
Subject: Re: Understanding log levels



On May 8, 2008, at 8:23 AM, Tasso Angelidis wrote:

 So as an example?

 class MyClass
 {
   Logger eventLogger = Logger.getLogger(MyClass.EventLogger);
   Logger opsLogger = Logger.getLogger(MyClass.OpsLogger);


   void someMethod()
   {
   eventLogeger.warn(Server stoppped);
   opsLogger.warn(Server stoppped);
   }
 }


 Isn't that double the work now? What if I want to have the  
 EventLogger writting to fileXYZ some events and then when I call  
 OpsLogger.Warn() it sends out the e-mail and also writes the message  
 to fileXYZ.

 Is this logger nesting? I.e: my OpsLogger should be a child of  
 EventLogger?

 Thanks


Like defining a directory structure, you have to choose which  
organizational principle is more significant.

If you chose a pattern like operations. + classname, you can route  
all operations related messages to the same place by attaching an  
appender to the operations logger.  If you want all messages related  
to a single class going to the same place, then you'd need to attach  
one appender to both operations.com.example.SomeClass and  
com.example.SomeClass.

If you chose a pattern like classname + .operations or  
.OpsLogger,  you can route all messages related to a specific class  
by attaching an appender to the classname.  However, routing all  
operations related messages to the same place would require attaching  
an appender at multiple places in the hierarchy  
(com.example.SomeClass.operations, com.example.OtherClass.operations,  
etc).

I'm assuming that operations related messages are far less frequent  
that other log messages and the people consuming the diagnostic logs  
would not be offended to see the operations related messages.  That  
would suggest attaching a file appender to the root logger which would  
receive all log messages, operations or otherwise, and an SMTP  
appender that would only process messages logged to an operations  
logger or child.

In your example, eventLogger and opsLogger are siblings, both share  
the same parent the logger named MyClass.

There is no need to log the same message twice.  You can design the  
names of the loggers you use so that one message is processed by two  
different appenders.

So I would suggest:

class MyClass {
 Logger logger = Logger.getLogger(MyClass.class);
 Logger opsLogger = Logger.getLogger(operations. +  
MyClass.class.getName());

void shutdown() {
 opsLogger.warn(Server stopped);
}

void start() {
 opsLogger.info(Server started);
}

void other renderPage() {
 logger.info(Rendering page);
 ...
}
}



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Appender events and levels.

2008-05-13 Thread Tasso Angelidis
I wrote my own SMTP appender as I required some additional functionality.

Bassically in void append(LoggingEvent event) I want to append the Level to the 
subject of the email.

String subject  = new String(My Subject);
subject +=  ( + event.getLevel().toString() + );


In my application:

opsLogger.info(test1); Produces subject: My Subject (ERROR) (INFO)

opsLogger.error(test2);  Produces subject: My Subject (ERROR)

opsLogger.warn(test3);  Produces subject: My Subject (ERROR) (INFO) 
(WARN)


How can I get the appender to only write the specific Level not the hiarchy.


I have log4j configured as follows...

appender name=log class=org.apache.log4j.RollingFileAppender
param name=Threshold value=info/

...
/appender

appender name=error class=org.apache.log4j.RollingFileAppender
param name=Threshold value=error/

...
/appender

appender name=ops class=com.pt.log4j.SMTPAppender
param name=Threshold value=info/

...
/appender 

logger name=operations.com.rbs
appender-ref ref=ops/
/logger   

root
level value=info /
appender-ref ref=log/
appender-ref ref=error/
/root 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Understanding log levels

2008-05-08 Thread Tasso Angelidis
So as an example?

class MyClass
{
Logger eventLogger = Logger.getLogger(MyClass.EventLogger);
Logger opsLogger = Logger.getLogger(MyClass.OpsLogger);


void someMethod()
{
eventLogeger.warn(Server stoppped);
opsLogger.warn(Server stoppped);
}
}


Isn't that double the work now? What if I want to have the EventLogger writting 
to fileXYZ some events and then when I call OpsLogger.Warn() it sends out the 
e-mail and also writes the message to fileXYZ.

Is this logger nesting? I.e: my OpsLogger should be a child of EventLogger?

Thanks

-Original Message-
From: Curt Arnold [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 07, 2008 12:09 PM
To: Log4J Users List
Subject: Re: Understanding log levels



On May 7, 2008, at 10:22 AM, Tasso Angelidis wrote:

 Hi, I'm currently working on a custom level and logger to send my  
 operations team an e-mail when an error occurs or when an operation  
 log is explicitely written. For instance: logger.operations(Server  
 was shutdown manually.);

 If I call logger.error(...) The log is recorded in my error log  
 and an e-mail is sent. As expected.
 If I call logger.operations(...) The log is written to the error  
 and smtp appenders, when it should only be the SMTP appender. It  
 shouldn't be logged as an error.

 Have I done something wrong or is it simply a config issue?

 Thanks



The better way is to use the logger name to represent the audience or  
topic, not a custom level.  That is exactly what the logger hierarchy  
was designed to represent.  It is just that it is so common to use  
class names as topics that people think that is the only thing that a  
logger name can be.  This question is asked repeatedly in different  
forms, like http://permalink.gmane.org/gmane.comp.jakarta.log4j.user/15285 
.

My suggestion would be to have a separate logger named operations. +  
class name and attach your SMTP appender to the operations logger.
If you use the logger hierarchy as intended, you can use level as  
intended and allow for INFO, WARN or ERROR severities in your  
operations logging.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Understanding log levels

2008-05-07 Thread Tasso Angelidis
Hi, I'm currently working on a custom level and logger to send my operations 
team an e-mail when an error occurs or when an operation log is explicitely 
written. For instance: logger.operations(Server was shutdown manually.);

If I call logger.error(...) The log is recorded in my error log and an e-mail 
is sent. As expected.
If I call logger.operations(...) The log is written to the error and smtp 
appenders, when it should only be the SMTP appender. It shouldn't be logged as 
an error.

Have I done something wrong or is it simply a config issue?

Thanks

My custom level...

public class OpsLevel extends Level
{
private static final long serialVersionUID = -9029242202525752834L;

static public final int OPS_INT   = Level.FATAL_INT + 1;
private static String OPS_STR  = OPS;

public static final OpsLevel OPS = new OpsLevel(OPS_INT, OPS_STR, 7);

...
}

My custom logger...

public class OpsLogger extends Logger
{

static String FQCN = OpsLogger.class.getName() + .;

private static OpsLoggerFactory opsFactory = new OpsLoggerFactory();

public OpsLogger(String name)
{
super(name);
}

public static Logger getLogger(String name)
{
return Logger.getLogger(name, opsFactory); 
}

public void operations(Object message)
{
super.log(FQCN, OpsLevel.OPS, message, null); 
}
}

Config file...

log4j:configuration xmlns:log4j=http://jakarta.apache.org/log4j/;

...

appender name=error_log class=org.apache.log4j.RollingFileAppender
param name=Threshold value=error/

...
/appender

appender name=ops class=com.MyCompany.log4j.MySMTPAppender -- 
This is right I have my own SMTP appender.
param name=Threshold value=error/

...
/appender 

category name=com.MyCompany.Scheduler
appender-ref ref=error_log/
appender-ref ref=ops/
/category


root
level value=info /
/root

loggerFactory class=com.MyCompany.log4j.OpsLoggerFactory /
/log4j:configuration

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]