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 Ole Ersoy <ol...@gmail.com> on 2008/10/20 06:06:29 UTC

Using the SyslogAppender

Hi,

I'm attempting to setup an test for logging with syslog to /var/log/test.log. So far I have this:

public class Log4JTest 
    extends TestCase
{
	Logger logger = Logger.getLogger(Log4JTest.class.getName());
	
	
	
	public void setUp()
	{

		SyslogAppender syslogAppender = new SyslogAppender();
		
		BasicConfigurator.configure();
		
		logger.addAppender(syslogAppender);
		
		syslogAppender.setSyslogHost("localhost");
		
		syslogAppender.setFacility("?????");
		
		syslogAppender.setLayout(new PatternLayout());

	}
    public void testApp()
    {
    	logger.info("I'm logging with syslog");
     }
}

Does anyone know what I need to pass to setFacility, and whether I need to make any adjustments in /etc/rsyslog.conf for this to work?

Thanks,
- Ole





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


Re: Using the SyslogAppender

Posted by Ole Ersoy <ol...@gmail.com>.
Hello again,

Been trying to trouble shoot my syslog testing.  I turned off iptables completely just to make sure it was not getting in the way.  I then added the following to my /etc/rsyslog.conf file to make sure that even remote clients can log:

# Options to syslogd
# -m 0 disables 'MARK' messages.
# -r enables logging from remote machines
# -x disables DNS lookups on messages received with -r
# See syslogd(8) for more details

SYSLOGD_OPTIONS="-m 0 -r -x"

I then restarted syslog:

/sbin/service syslog restart

I also checked to make sure messages with level info go to /var/log/messages

My configuration for this looks like this:

*.info;mail.none;authpriv.none;cron.none                /var/log/messages

Which I think means that all messages with level info will end up in /var/log/messages, except for those from mail, authpriv, and cron.

I then tried running my test (Below), but the there's still no message in /var/log/messages.  Any ideas?

Thanks,
- Ole

The Test:

/**
 * Unit test for simple App.
 */
public class Log4JTest 
    extends TestCase
{
	Logger logger = Logger.getLogger(Log4JTest.class.getName());
	
	SyslogAppender syslogAppender = new SyslogAppender();

	public void setUp()
	{
		BasicConfigurator.configure();
		
		syslogAppender.setSyslogHost("localhost");
		
		syslogAppender.setFacility("LOCAL0");
		
		syslogAppender.setLayout(new PatternLayout());
		
        syslogAppender.activateOptions();
        
        logger.addAppender(syslogAppender); 
	}
    public void testApp()
    {
    	logger.info("I'm logging with syslog");
     }
}

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


Re: Using the SyslogAppender

Posted by Ole Ersoy <ol...@gmail.com>.
Curt and Christian,

Thanks for all the tips.  I made sure the syslog port is open and modified the setup to look like this:

	BasicConfigurator.configure();
	
	syslogAppender.setSyslogHost("localhost");
	
	syslogAppender.setFacility("LOCAL0");
		
	syslogAppender.setLayout(new PatternLayout());
		
        syslogAppender.activateOptions();
        
        logger.addAppender(syslogAppender); 

However I'm not really sure where to look for the output.  I tried "tail /var/log/messages", but there was nothing there.  I'm sure "LOCAL0" corresponds to a log file, but I'm not sure which one.  I'd also like to tell syslog to create /var/log/test.log and have the log record go to this file.  Any ideas on how to accomplish this?

Thanks again,
- Ole


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


RE: Using the SyslogAppender

Posted by "Berwanger, Christian" <ch...@logica.com>.
Hi Ole,

You have to pass there one of the following listed strings depending
which category you want to log the message 

 "LOCAL0" 
 "LOCAL1" 
 "LOCAL2" 
 "LOCAL3" 
 "LOCAL4" 
 "LOCAL5" 
 "LOCAL6" 
 "LOCAL7" 

You could later configure filters in order to store messages with the
same facility id in one folder.

Please confirm as well that the syslog port is open for the local
machine otherwise you will not receive messages on the local machine.

Does it work?

Christian 


-----Original Message-----
From: Ole Ersoy [mailto:ole.ersoy@gmail.com] 
Sent: 20 October 2008 06:06
To: log4j-user@logging.apache.org
Subject: Using the SyslogAppender

Hi,

I'm attempting to setup an test for logging with syslog to
/var/log/test.log. So far I have this:

public class Log4JTest 
    extends TestCase
{
	Logger logger = Logger.getLogger(Log4JTest.class.getName());
	
	
	
	public void setUp()
	{

		SyslogAppender syslogAppender = new SyslogAppender();
		
		BasicConfigurator.configure();
		
		logger.addAppender(syslogAppender);
		
		syslogAppender.setSyslogHost("localhost");
		
		syslogAppender.setFacility("?????");
		
		syslogAppender.setLayout(new PatternLayout());

	}
    public void testApp()
    {
    	logger.info("I'm logging with syslog");
     }
}

Does anyone know what I need to pass to setFacility, and whether I need
to make any adjustments in /etc/rsyslog.conf for this to work?

Thanks,
- Ole





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



This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.



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


Re: Using the SyslogAppender

Posted by Curt Arnold <ca...@apache.org>.
On Oct 19, 2008, at 11:06 PM, Ole Ersoy wrote:

> Hi,
>
> I'm attempting to setup an test for logging with syslog to /var/log/ 
> test.log. So far I have this:
>
> public class Log4JTest    extends TestCase
> {
> 	Logger logger = Logger.getLogger(Log4JTest.class.getName());
> 	
> 	
> 	
> 	public void setUp()
> 	{
>
> 		SyslogAppender syslogAppender = new SyslogAppender();
> 		
> 		BasicConfigurator.configure();


BasicConfigurator creates a ConsoleAppender and attaches it to the  
root logger.


>
> 		
> 		logger.addAppender(syslogAppender);
> 		
> 		syslogAppender.setSyslogHost("localhost");
> 		
> 		syslogAppender.setFacility("?????");
> 		
> 		syslogAppender.setLayout(new PatternLayout());


activateOptions() should be called after properties are set to make  
them effective.  I'd suggest removing the earlier logger.addAppender()  
and adding:

                     syslogAppender.activateOptions();
                     logger.addAppender(syslogAppender);

>
>
> 	}
>   public void testApp()
>   {
>   	logger.info("I'm logging with syslog");
>    }
> }
>
> Does anyone know what I need to pass to setFacility, and whether I  
> need to make any adjustments in /etc/rsyslog.conf for this to work?
>
> Thanks,
> - Ole
>

As mentioned in the previous email, SyslogAppender writes to a network  
socket to perform syslogging even when logging to the local machine.   
Any other approach would require native code.  There is a feature  
request for a native code SyslogAppender, but there has not been any  
activity.

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