Package org.apache.log4j.net
Class SyslogAppender
- java.lang.Object
-
- org.apache.log4j.AppenderSkeleton
-
- org.apache.log4j.net.SyslogAppender
-
- All Implemented Interfaces:
Appender,OptionHandler
public class SyslogAppender extends AppenderSkeleton
Use SyslogAppender to send log messages to a remote syslog daemon.
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.SimpleDateFormatdateFormatDate format used if header = true.protected static intFACILITY_OI(package private) booleanfacilityPrinting(package private) java.lang.StringfacilityStrprivate booleanheaderIf true, the appender will generate the HEADER (timestamp and host name) part of the syslog packet.private booleanlayoutHeaderCheckedSet to true after the header of the layout has been sent or if it has none.private java.lang.StringlocalHostnameHost name used to identify messages from this appender.static intLOG_AUTHsecurity/authorization messagesstatic intLOG_AUTHPRIVsecurity/authorization messages (private)static intLOG_CRONclock daemonstatic intLOG_DAEMONSystem daemonsstatic intLOG_FTPftp daemonstatic intLOG_KERNKernel messagesstatic intLOG_LOCAL0reserved for local usestatic intLOG_LOCAL1reserved for local usestatic intLOG_LOCAL2reserved for local usestatic intLOG_LOCAL3reserved for local usestatic intLOG_LOCAL4reserved for local usestatic intLOG_LOCAL5reserved for local usestatic intLOG_LOCAL6reserved for local usestatic intLOG_LOCAL7reserved for local usestatic intLOG_LPRline printer subsystemstatic intLOG_MAILMail systemstatic intLOG_NEWSnetwork news subsystemstatic intLOG_SYSLOGmessages generated internally by syslogdstatic intLOG_USERRandom user-level messagesstatic intLOG_UUCPUUCP subsystem(package private) SyslogQuietWritersqwprotected static intSYSLOG_HOST_OI(package private) intsyslogFacility(package private) java.lang.StringsyslogHost(package private) static java.lang.StringTAB-
Fields inherited from class org.apache.log4j.AppenderSkeleton
closed, errorHandler, headFilter, layout, name, tailFilter, threshold
-
-
Constructor Summary
Constructors Constructor Description SyslogAppender()SyslogAppender(Layout layout, int syslogFacility)SyslogAppender(Layout layout, java.lang.String syslogHost, int syslogFacility)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateOptions()This method returns immediately as options are activated when they are set.voidappend(LoggingEvent event)Subclasses ofAppenderSkeletonshould implement this method to perform actual logging.voidclose()Release any resources held by this SyslogAppender.java.lang.StringgetFacility()Returns the value of the Facility option.static intgetFacility(java.lang.String facilityName)Returns the integer value corresponding to the named syslog facility, or -1 if it couldn't be recognized.booleangetFacilityPrinting()Returns the value of the FacilityPrinting option.static java.lang.StringgetFacilityString(int syslogFacility)Returns the specified syslog facility as a lower-case String, e.g.booleangetHeader()If true, the appender will generate the HEADER part (that is, timestamp and host name) of the syslog packet.private java.lang.StringgetLocalHostname()Get the host name used to identify this appender.private java.lang.StringgetPacketHeader(long timeStamp)Gets HEADER portion of packet.java.lang.StringgetSyslogHost()Returns the value of the SyslogHost option.private voidinitSyslogFacilityStr()booleanrequiresLayout()The SyslogAppender requires a layout.private voidsendLayoutMessage(java.lang.String msg)Set header or footer of layout.voidsetFacility(java.lang.String facilityName)Set the syslog facility.voidsetFacilityPrinting(boolean on)If the FacilityPrinting option is set to true, the printed message will include the facility name of the application.voidsetHeader(boolean val)Returns whether the appender produces the HEADER part (that is, timestamp and host name) of the syslog packet.voidsetSyslogHost(java.lang.String syslogHost)The SyslogHost option is the name of the the syslog host where log output should go.private voidsplitPacket(java.lang.String header, java.lang.String packet)-
Methods inherited from class org.apache.log4j.AppenderSkeleton
addFilter, clearFilters, doAppend, finalize, getErrorHandler, getFilter, getFirstFilter, getLayout, getName, getThreshold, isAsSevereAsThreshold, setErrorHandler, setLayout, setName, setThreshold
-
-
-
-
Field Detail
-
LOG_KERN
public static final int LOG_KERN
Kernel messages- See Also:
- Constant Field Values
-
LOG_USER
public static final int LOG_USER
Random user-level messages- See Also:
- Constant Field Values
-
LOG_MAIL
public static final int LOG_MAIL
Mail system- See Also:
- Constant Field Values
-
LOG_DAEMON
public static final int LOG_DAEMON
System daemons- See Also:
- Constant Field Values
-
LOG_AUTH
public static final int LOG_AUTH
security/authorization messages- See Also:
- Constant Field Values
-
LOG_SYSLOG
public static final int LOG_SYSLOG
messages generated internally by syslogd- See Also:
- Constant Field Values
-
LOG_LPR
public static final int LOG_LPR
line printer subsystem- See Also:
- Constant Field Values
-
LOG_NEWS
public static final int LOG_NEWS
network news subsystem- See Also:
- Constant Field Values
-
LOG_UUCP
public static final int LOG_UUCP
UUCP subsystem- See Also:
- Constant Field Values
-
LOG_CRON
public static final int LOG_CRON
clock daemon- See Also:
- Constant Field Values
-
LOG_AUTHPRIV
public static final int LOG_AUTHPRIV
security/authorization messages (private)- See Also:
- Constant Field Values
-
LOG_FTP
public static final int LOG_FTP
ftp daemon- See Also:
- Constant Field Values
-
LOG_LOCAL0
public static final int LOG_LOCAL0
reserved for local use- See Also:
- Constant Field Values
-
LOG_LOCAL1
public static final int LOG_LOCAL1
reserved for local use- See Also:
- Constant Field Values
-
LOG_LOCAL2
public static final int LOG_LOCAL2
reserved for local use- See Also:
- Constant Field Values
-
LOG_LOCAL3
public static final int LOG_LOCAL3
reserved for local use- See Also:
- Constant Field Values
-
LOG_LOCAL4
public static final int LOG_LOCAL4
reserved for local use- See Also:
- Constant Field Values
-
LOG_LOCAL5
public static final int LOG_LOCAL5
reserved for local use- See Also:
- Constant Field Values
-
LOG_LOCAL6
public static final int LOG_LOCAL6
reserved for local use- See Also:
- Constant Field Values
-
LOG_LOCAL7
public static final int LOG_LOCAL7
reserved for local use- See Also:
- Constant Field Values
-
SYSLOG_HOST_OI
protected static final int SYSLOG_HOST_OI
- See Also:
- Constant Field Values
-
FACILITY_OI
protected static final int FACILITY_OI
- See Also:
- Constant Field Values
-
TAB
static final java.lang.String TAB
- See Also:
- Constant Field Values
-
syslogFacility
int syslogFacility
-
facilityStr
java.lang.String facilityStr
-
facilityPrinting
boolean facilityPrinting
-
sqw
SyslogQuietWriter sqw
-
syslogHost
java.lang.String syslogHost
-
header
private boolean header
If true, the appender will generate the HEADER (timestamp and host name) part of the syslog packet.- Since:
- 1.2.15
-
dateFormat
private final java.text.SimpleDateFormat dateFormat
Date format used if header = true.- Since:
- 1.2.15
-
localHostname
private java.lang.String localHostname
Host name used to identify messages from this appender.- Since:
- 1.2.15
-
layoutHeaderChecked
private boolean layoutHeaderChecked
Set to true after the header of the layout has been sent or if it has none.
-
-
Method Detail
-
close
public void close()
Release any resources held by this SyslogAppender.- Since:
- 0.8.4
-
initSyslogFacilityStr
private void initSyslogFacilityStr()
-
getFacilityString
public static java.lang.String getFacilityString(int syslogFacility)
Returns the specified syslog facility as a lower-case String, e.g. "kern", "user", etc.
-
getFacility
public static int getFacility(java.lang.String facilityName)
Returns the integer value corresponding to the named syslog facility, or -1 if it couldn't be recognized.- Parameters:
facilityName- one of the strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. The matching is case-insensitive.- Since:
- 1.1
-
splitPacket
private void splitPacket(java.lang.String header, java.lang.String packet)
-
append
public void append(LoggingEvent event)
Description copied from class:AppenderSkeletonSubclasses ofAppenderSkeletonshould implement this method to perform actual logging. See alsoAppenderSkeleton.doAppendmethod.- Specified by:
appendin classAppenderSkeleton
-
activateOptions
public void activateOptions()
This method returns immediately as options are activated when they are set.- Specified by:
activateOptionsin interfaceOptionHandler- Overrides:
activateOptionsin classAppenderSkeleton
-
requiresLayout
public boolean requiresLayout()
The SyslogAppender requires a layout. Hence, this method returnstrue.- Since:
- 0.8.4
-
setSyslogHost
public void setSyslogHost(java.lang.String syslogHost)
The SyslogHost option is the name of the the syslog host where log output should go. A non-default port can be specified by appending a colon and port number to a host name, an IPv4 address or an IPv6 address enclosed in square brackets. WARNING If the SyslogHost is not set, then this appender will fail.
-
getSyslogHost
public java.lang.String getSyslogHost()
Returns the value of the SyslogHost option.
-
setFacility
public void setFacility(java.lang.String facilityName)
Set the syslog facility. This is the Facility option.The
facilityNameparameter must be one of the strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. Case is unimportant.- Since:
- 0.8.1
-
getFacility
public java.lang.String getFacility()
Returns the value of the Facility option.
-
setFacilityPrinting
public void setFacilityPrinting(boolean on)
If the FacilityPrinting option is set to true, the printed message will include the facility name of the application. It is false by default.
-
getFacilityPrinting
public boolean getFacilityPrinting()
Returns the value of the FacilityPrinting option.
-
getHeader
public final boolean getHeader()
If true, the appender will generate the HEADER part (that is, timestamp and host name) of the syslog packet. Default value is false for compatibility with existing behavior, however should be true unless there is a specific justification.- Since:
- 1.2.15
-
setHeader
public final void setHeader(boolean val)
Returns whether the appender produces the HEADER part (that is, timestamp and host name) of the syslog packet.- Since:
- 1.2.15
-
getLocalHostname
private java.lang.String getLocalHostname()
Get the host name used to identify this appender.- Returns:
- local host name
- Since:
- 1.2.15
-
getPacketHeader
private java.lang.String getPacketHeader(long timeStamp)
Gets HEADER portion of packet.- Parameters:
timeStamp- number of milliseconds after the standard base time.- Returns:
- HEADER portion of packet, will be zero-length string if header is false.
- Since:
- 1.2.15
-
sendLayoutMessage
private void sendLayoutMessage(java.lang.String msg)
Set header or footer of layout.- Parameters:
msg- message body, may not be null.
-
-