1
0
Fork 0

init commit logstats bsd source

This commit is contained in:
Willem Cazander 2012-01-03 02:49:12 +01:00
parent 00a52478df
commit 99c93dbc0c
105 changed files with 8422 additions and 1 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>logstats-jboss-sar</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
#Mon Jan 02 23:18:49 CET 2012
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,6 @@
#Sat Jun 12 01:12:26 CEST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,5 @@
#Mon Jan 02 23:18:47 CET 2012
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,9 @@
#Sat Jun 12 01:12:25 CEST 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

View file

@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>logstats</artifactId>
<groupId>net.forwardfire.logstats</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>logstats-jboss-sar</artifactId>
<packaging>jboss-sar</packaging>
<name>logstats-jboss-sar</name>
<description>logstats-jboss-sar</description>
<!--
<properties>
<version.org.jboss.mx>6.0.0.Beta5</version.org.jboss.mx>
<version.org.jboss.naming>5.0.5.Final</version.org.jboss.naming>
<version.org.jboss.logging>3.0.0.Beta2</version.org.jboss.logging>
</properties>
-->
<dependencies>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-system-jmx</artifactId>
<version>5.1.0.GA</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,67 @@
package net.forwardfire.logstats.jboss.log4j;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
import org.jboss.logging.Logger;
/**
* Appends log4j messages to the logService MBean
*
* @author Willem Cazander
* @version 1.0 Jun 09, 2010
*/
public class DataSourceLog4jAppender extends AppenderSkeleton {
private DataSourceLogService logService = null;
private Logger logger = Logger.getLogger(DataSourceLog4jAppender.class.getName());
/**
* constructor
* @throws Exception
*/
public DataSourceLog4jAppender(DataSourceLogService logService) {
super();
if (logService==null) {
throw new NullPointerException("Can't start with null logService.");
}
this.logService=logService;
setName(logService.getLog4jAppenderName());
logger.info("Created DataSourceLog4jAppender with name: "+getName());
}
/**
* Closes this appender privately.
*/
public void shutdown() {
logService = null;
logger.info("Closed DataSourceLog4jAppender with name: "+getName());
}
/**
* Closes this appender but is left empty because of fake call.
*/
public void close() {
}
/**
* Put LoggingEvent in queue for processing.
*/
public void append(LoggingEvent event) {
if (logService==null) {
return;
}
try {
logService.putLoggingEvent(event);
} catch (InterruptedException e) {
// we don't log in appender, in case of loop.
}
}
/**
* DataSourceLog4jAppender don't require a layout.
*/
public boolean requiresLayout() {
return false;
}
}

View file

@ -0,0 +1,222 @@
package net.forwardfire.logstats.jboss.log4j;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.jboss.logging.Logger;
/**
* Perists the messages of the queue
*
* @author Willem Cazander
* @version 1.0 Jun 09, 2010
*/
public class DataSourceLogPersistThread extends Thread {
private DataSourceLogService logService = null;
private Logger logger = Logger.getLogger(DataSourceLogPersistThread.class.getName());
/**
* Constructor with the LogService
* @param logService
*/
public DataSourceLogPersistThread(DataSourceLogService logService) {
this.logService = logService;
}
/**
* Perists the messages of the queue
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
long idleTimer = System.currentTimeMillis();
// setup DB connection from datasource
Connection conn = null;
try {
conn = getConnection();
} catch (SQLException e) {
logger.error("init getConnection failed, error: "+e.getMessage(),e);
return;
} catch (NamingException e) {
logger.error("init getConnection datasource lookup failed, error: "+e.getMessage(),e);
return;
}
// Get hostname setup
String hostname = null;
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
logger.error("init getLocalHost failed, error: "+e.getMessage(),e);
try {
conn.close();
} catch (SQLException se) {
logger.warn("init connection close failed, SQLException: "+se.getMessage(),e);
}
return;
}
if (logService.getBackendHostname()!=null && logService.getBackendHostname().isEmpty()==false) {
hostname = logService.getBackendHostname();
}
// Test and record out one thread
try {
storeLogData(conn,hostname,System.currentTimeMillis(),Level.DEBUG.toInt(),this.getClass().getName(),"Startup and connection of thread: "+getName());
} catch (SQLException e) {
logger.error("test connection message error: "+e.getMessage(),e);
try {
if (conn!=null && conn.isClosed()==false) {
conn.close();
}
} catch (SQLException se) {
logger.warn("test connection close failed, SQLException: "+se.getMessage(),se);
}
return;
}
// main loop
int errorCount = 0;
while (isInterrupted()==false) {
LoggingEvent logMessage = null;
try {
logMessage = logService.pollLoggingEvent();
} catch (InterruptedException e) {
break;
}
if (logMessage!=null) {
try {
// convert
String message = convertMessage(logMessage.getMessage());
// persist message
storeLogData( conn,hostname,logMessage.timeStamp,logMessage.getLevel().toInt(),logMessage.getLoggerName(),message );
} catch (SQLException se) {
if (errorCount==0) {
logger.error("storeLogData() failed, error: "+se.getMessage());
}
errorCount++;
if (errorCount>1000) {
logger.error("storeLogData() failed 1000 times, last error: "+se.getMessage());
errorCount=0;
}
}
} else {
if (checkConnection(conn) == false) {
try {
if (conn!=null && conn.isClosed()==false) {
conn.close();
}
} catch (SQLException se) {
logger.warn("connection close failed, SQLException: "+se.getMessage(),se);
}
try {
conn = getConnection();
} catch (Exception ee) {
logger.error("failure in getConnection() error:"+ee.getMessage(),ee);
break;
}
} else {
if (logService.getBackendIdleMarkerTime()>0) {
// check for update of idle timer
if ((System.currentTimeMillis()-idleTimer) > logService.getBackendIdleMarkerTime()*1000) {
idleTimer = System.currentTimeMillis();
logger.info(logService.getBackendIdleMarkerMessage()+" thread: "+getName());
}
}
}
}
}
// exit thread
logger.info("shutdown thread: "+getName());
try {
if (conn!=null && conn.isClosed()==false) {
conn.close();
}
} catch (SQLException e) {
logger.warn("connection close failed, SQLException: "+e.getMessage());
}
}
private Connection getConnection() throws SQLException,NamingException {
String dataSourceName = logService.getBackendDataSource();
logger.debug("Getting connection from datasource: "+dataSourceName+" for thread: "+getName());
Context naming = new InitialContext();
DataSource dataSource = (DataSource) naming.lookup(dataSourceName);
return dataSource.getConnection();
}
public boolean checkConnection(Connection connection) {
if (connection==null) {
return false;
}
try {
return connection.prepareStatement(logService.getBackendKeepAliveQuery()).execute();
} catch (SQLException e) {
logger.error("checkConnection: SQLException: "+e.getMessage(),e);
return false;
}
}
/**
* Message is not always a string so check for some types we can handle.
*
* @param messageObj
* @return
*/
private String convertMessage(Object messageObj) {
String message = null;
if (messageObj == null ) {
message = "NULL";
} else if (messageObj instanceof String) {
message = (String)messageObj;
} else if (messageObj instanceof Exception) {
message = ((Exception)messageObj).getMessage();
} else {
message = messageObj.toString();
}
return message;
}
private void storeLogData(Connection connection,String host,long time, int level, String source, String message) throws SQLException {
PreparedStatement stmt = null;
Timestamp timeStamp = new Timestamp(time);
stmt = connection.prepareStatement(logService.getBackendLogQuery());
String para = logService.getBackendLogQueryParameters();
String[] paras = para.split(",");
for (int i=1;i<=paras.length;i++) {
String col = paras[i-1];
if ("time".equals(col)) {
stmt.setTimestamp(i, timeStamp);
} else if ("level".equals(col)) {
stmt.setInt(i, level);
} else if ("host".equals(col)) {
stmt.setString(i, host);
} else if ("source".equals(col)) {
stmt.setString(i, source);
} else if ("message".equals(col)) {
stmt.setString(i, message);
} else {
throw new IllegalArgumentException("Unknow column: "+col+" on index: "+i);
}
}
stmt.execute();
}
}

View file

@ -0,0 +1,433 @@
package net.forwardfire.logstats.jboss.log4j;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import javax.xml.parsers.FactoryConfigurationError;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.logging.util.OnlyOnceErrorHandler;
import org.jboss.system.ServiceMBeanSupport;
/**
* Jboss MBean which hooks DB logger to log4j and depends on a datasource for db access.
*
* Orginal idea was made by Edward Pilipczuk <exedx@aster.pl>
*
* @author Willem Cazander
* @version 1.0 Jun 09, 2010
*/
public class DataSourceLogService extends ServiceMBeanSupport implements DataSourceLogServiceMBean {
// backend config options
private String backendDataSource = null;
private String backendLogQuery = "INSERT INTO log_data (log_date, log_level,hostname, source, message) VALUES (?,?,?,?,?)";
private String backendLogQueryParameters = "time,level,host,source,message";
private String backendHostname = null;
private int backendThreads = 3;
private int backendMaxQueueSize = 1500;
private int backendKeepAliveTimeout = 300;
private String backendKeepAliveQuery = "SELECT 1";
private int backendIdleMarkerTime = 3600;
private String backendIdleMarkerMessage = "--- Mark ---";
private boolean backendStatisticsLog = true;
private int backendStatisticsLogTime = 300;
// log4j config options
private String log4jParseConfigResource = "META-INF/logstats-log4j.xml";
private String log4jAppenderName = "LOGSTATS";
private boolean log4jAppenderAutoAdd = true;
private boolean log4jAppenderAutoAddOnlyOnceError = true;
private boolean log4jAppenderToRoot = true;
// stats counters
private int statsMessagesTotal = 0;
private int statsMessagesDropped = 0;
// Internal state objects
volatile private boolean running = false;
private BlockingQueue<LoggingEvent> messageQueue = null;
private DataSourceLog4jAppender appender = null;
private List<DataSourceLogPersistThread> persistThreads = null;
// ===== Override ServiceMBeanSupport methods
@Override
protected void startService() throws Exception {
messageQueue = new LinkedBlockingQueue<LoggingEvent>(backendMaxQueueSize);
startLog4j();
startBackend();
running = true;
log.info("DataSourceLogService started; queueSize: "+backendMaxQueueSize+" threads: "+backendThreads);
}
@Override
protected void stopService() throws Exception {
running = false;
try {
stopLog4j();
} catch (Exception e) {
log.warn("Error in stopLog4j: "+e.getMessage());
} finally {
try {
stopBackend();
} catch (Exception e) {
log.warn("Error in stopBackend: "+e.getMessage());
} finally {
log.info("DataSourceLogService stopped.");
}
}
}
// =========== Private methods
private void startBackend() {
persistThreads = new ArrayList<DataSourceLogPersistThread>(backendThreads);
for (int i=0;i<backendThreads;i++) {
DataSourceLogPersistThread worker = new DataSourceLogPersistThread(this);
worker.start();
persistThreads.add(worker);
}
}
private void stopBackend() {
for (DataSourceLogPersistThread worker:persistThreads) {
worker.interrupt();
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
log.warn("Interrupted while wait until backend threads are done.");
}
persistThreads.clear();
messageQueue.clear();
}
private void startLog4j() {
appender = new DataSourceLog4jAppender(this);
if (log4jAppenderAutoAddOnlyOnceError) {
appender.setErrorHandler(new OnlyOnceErrorHandler());
log.debug("Added OnlyOnceErrorHandler to appender: "+appender.getName());
}
if (log4jAppenderAutoAdd) {
Logger.getRootLogger().addAppender(appender);
log.debug("Added appender: "+appender.getName()+" to root logger.");
}
if (log4jParseConfigResource!=null && log4jParseConfigResource.isEmpty()==false) {
try {
InputStream lis = Thread.currentThread().getContextClassLoader().getResourceAsStream(log4jParseConfigResource);
new DOMConfigurator().doConfigure(lis,LogManager.getLoggerRepository());
log.debug("Loaded config for log4j: "+log4jParseConfigResource);
} catch (FactoryConfigurationError e) {
log.warn("Error while configing log4j from "+log4jParseConfigResource+" error: "+e.getMessage());
}
}
}
private void stopLog4j() {
Logger.getRootLogger().removeAppender(appender);
appender.shutdown();
appender = null;
}
// ============== Protected methods
protected boolean isRunning() {
return running;
}
protected void putLoggingEvent(LoggingEvent event) throws InterruptedException {
if (running==false) {
return;
}
if (messageQueue==null) {
throw new IllegalStateException("LogService is not started");
}
statsMessagesTotal++;
if (messageQueue.remainingCapacity()>0) {
messageQueue.put(event);
} else {
statsMessagesDropped++;
}
}
protected LoggingEvent pollLoggingEvent() throws InterruptedException {
if (messageQueue==null) {
throw new IllegalStateException("LogService is not started");
}
return messageQueue.poll(backendKeepAliveTimeout, TimeUnit.SECONDS);
}
// ============== MBean methods
/**
* Resets the stats counters
*/
public void resetStatsCounters() {
statsMessagesTotal = 0;
statsMessagesDropped = 0;
}
/**
* @return the statsMessagesTotal
*/
public int getStatsMessagesTotal() {
return statsMessagesTotal;
}
/**
* @return the statsMessagesDropped
*/
public int getStatsMessagesDropped() {
return statsMessagesDropped;
}
/**
* @return the backendDataSource
*/
public String getBackendDataSource() {
return backendDataSource;
}
/**
* @param backendDataSource the backendDataSource to set
*/
public void setBackendDataSource(String backendDataSource) {
this.backendDataSource = backendDataSource;
}
/**
* @return the backendLogQuery
*/
public String getBackendLogQuery() {
return backendLogQuery;
}
/**
* @param backendLogQuery the backendLogQuery to set
*/
public void setBackendLogQuery(String backendLogQuery) {
this.backendLogQuery = backendLogQuery;
}
/**
* @return the backendLogQueryParameters
*/
public String getBackendLogQueryParameters() {
return backendLogQueryParameters;
}
/**
* @param backendLogQueryParameters the backendLogQueryParameters to set
*/
public void setBackendLogQueryParameters(String backendLogQueryParameters) {
this.backendLogQueryParameters = backendLogQueryParameters;
}
/**
* @return the backendHostname
*/
public String getBackendHostname() {
return backendHostname;
}
/**
* @param backendHostname the backendHostname to set
*/
public void setBackendHostname(String backendHostname) {
this.backendHostname = backendHostname;
}
/**
* @return the backendKeepAliveTimeout
*/
public int getBackendKeepAliveTimeout() {
return backendKeepAliveTimeout;
}
/**
* @param backendKeepAliveTimeout the backendKeepAliveTimeout to set
*/
public void setBackendKeepAliveTimeout(int backendKeepAliveTimeout) {
this.backendKeepAliveTimeout = backendKeepAliveTimeout;
}
/**
* @return the backendKeepAliveQuery
*/
public String getBackendKeepAliveQuery() {
return backendKeepAliveQuery;
}
/**
* @param backendKeepAliveQuery the backendKeepAliveQuery to set
*/
public void setBackendKeepAliveQuery(String backendKeepAliveQuery) {
this.backendKeepAliveQuery = backendKeepAliveQuery;
}
/**
* @return the backendThreads
*/
public int getBackendThreads() {
return backendThreads;
}
/**
* @param backendThreads the backendThreads to set
*/
public void setBackendThreads(int backendThreads) {
this.backendThreads = backendThreads;
}
/**
* @return the backendMaxQueueSize
*/
public int getBackendMaxQueueSize() {
return backendMaxQueueSize;
}
/**
* @param backendMaxQueueSize the backendMaxQueueSize to set
*/
public void setBackendMaxQueueSize(int backendMaxQueueSize) {
this.backendMaxQueueSize = backendMaxQueueSize;
}
/**
* @return the backendIdleMarkerTime
*/
public int getBackendIdleMarkerTime() {
return backendIdleMarkerTime;
}
/**
* @param backendIdleMarkerTime the backendIdleMarkerTime to set
*/
public void setBackendIdleMarkerTime(int backendIdleMarkerTime) {
this.backendIdleMarkerTime = backendIdleMarkerTime;
}
/**
* @return the backendIdleMarkerMessage
*/
public String getBackendIdleMarkerMessage() {
return backendIdleMarkerMessage;
}
/**
* @param backendIdleMarkerMessage the backendIdleMarkerMessage to set
*/
public void setBackendIdleMarkerMessage(String backendIdleMarkerMessage) {
this.backendIdleMarkerMessage = backendIdleMarkerMessage;
}
/**
* @return the backendStatisticsLog
*/
public boolean isBackendStatisticsLog() {
return backendStatisticsLog;
}
/**
* @param backendStatisticsLog the backendStatisticsLog to set
*/
public void setBackendStatisticsLog(boolean backendStatisticsLog) {
this.backendStatisticsLog = backendStatisticsLog;
}
/**
* @return the backendStatisticsLogTime
*/
public int getBackendStatisticsLogTime() {
return backendStatisticsLogTime;
}
/**
* @param backendStatisticsLogTime the backendStatisticsLogTime to set
*/
public void setBackendStatisticsLogTime(int backendStatisticsLogTime) {
this.backendStatisticsLogTime = backendStatisticsLogTime;
}
/**
* @return the log4jParseConfigResource
*/
public String getLog4jParseConfigResource() {
return log4jParseConfigResource;
}
/**
* @param log4jParseConfigResource the log4jParseConfigResource to set
*/
public void setLog4jParseConfigResource(String log4jParseConfigResource) {
this.log4jParseConfigResource = log4jParseConfigResource;
}
/**
* @return the log4jAppenderName
*/
public String getLog4jAppenderName() {
return log4jAppenderName;
}
/**
* @param log4jAppenderName the log4jAppenderName to set
*/
public void setLog4jAppenderName(String log4jAppenderName) {
this.log4jAppenderName = log4jAppenderName;
}
/**
* @return the log4jAppenderAutoAdd
*/
public boolean isLog4jAppenderAutoAdd() {
return log4jAppenderAutoAdd;
}
/**
* @param log4jAppenderAutoAdd the log4jAppenderAutoAdd to set
*/
public void setLog4jAppenderAutoAdd(boolean log4jAppenderAutoAdd) {
this.log4jAppenderAutoAdd = log4jAppenderAutoAdd;
}
/**
* @return the log4jAppenderAutoAddOnlyOnceError
*/
public boolean isLog4jAppenderAutoAddOnlyOnceError() {
return log4jAppenderAutoAddOnlyOnceError;
}
/**
* @param log4jAppenderAutoAddOnlyOnceError the log4jAppenderAutoAddOnlyOnceError to set
*/
public void setLog4jAppenderAutoAddOnlyOnceError(
boolean log4jAppenderAutoAddOnlyOnceError) {
this.log4jAppenderAutoAddOnlyOnceError = log4jAppenderAutoAddOnlyOnceError;
}
/**
* @return the log4jAppenderToRoot
*/
public boolean isLog4jAppenderToRoot() {
return log4jAppenderToRoot;
}
/**
* @param log4jAppenderToRoot the log4jAppenderToRoot to set
*/
public void setLog4jAppenderToRoot(boolean log4jAppenderToRoot) {
this.log4jAppenderToRoot = log4jAppenderToRoot;
}
}

View file

@ -0,0 +1,198 @@
package net.forwardfire.logstats.jboss.log4j;
import org.jboss.system.ServiceMBean;
/**
* Defines all configable options of the log service MBean
*
* @author Willem Cazander
* @version 1.0 Jun 09, 2010
*/
public interface DataSourceLogServiceMBean extends ServiceMBean {
/**
* Resets the stats counters
*/
public void resetStatsCounters();
/**
* @return the statsMessagesTotal
*/
public int getStatsMessagesTotal();
/**
* @return the statsMessagesDropped
*/
public int getStatsMessagesDropped();
/**
* @return the backendDataSource
*/
public String getBackendDataSource();
/**
* @param backendDataSource the backendDataSource to set
*/
public void setBackendDataSource(String backendDataSource);
/**
* @return the backendLogQuery
*/
public String getBackendLogQuery();
/**
* @param backendLogQuery the backendLogQuery to set
*/
public void setBackendLogQuery(String backendLogQuery);
/**
* @return the backendLogQueryParameters
*/
public String getBackendLogQueryParameters();
/**
* @param backendLogQueryParameters the backendLogQueryParameters to set
*/
public void setBackendLogQueryParameters(String backendLogQueryParameters);
/**
* @return the backendHostname
*/
public String getBackendHostname();
/**
* @param backendHostname the backendHostname to set
*/
public void setBackendHostname(String backendHostname);
/**
* @return the backendKeepAliveTimeout
*/
public int getBackendKeepAliveTimeout();
/**
* @param backendKeepAliveTimeout the backendKeepAliveTimeout to set
*/
public void setBackendKeepAliveTimeout(int backendKeepAliveTimeout);
/**
* @return the backendKeepAliveQuery
*/
public String getBackendKeepAliveQuery();
/**
* @param backendKeepAliveQuery the backendKeepAliveQuery to set
*/
public void setBackendKeepAliveQuery(String backendKeepAliveQuery);
/**
* @return the backendThreads
*/
public int getBackendThreads();
/**
* @param backendThreads the backendThreads to set
*/
public void setBackendThreads(int backendThreads);
/**
* @return the backendMaxQueueSize
*/
public int getBackendMaxQueueSize();
/**
* @param backendMaxQueueSize the backendMaxQueueSize to set
*/
public void setBackendMaxQueueSize(int backendMaxQueueSize);
/**
* @return the backendIdleMarkerTime
*/
public int getBackendIdleMarkerTime();
/**
* @param backendIdleMarkerTime the backendIdleMarkerTime to set
*/
public void setBackendIdleMarkerTime(int backendIdleMarkerTime);
/**
* @return the backendIdleMarkerMessage
*/
public String getBackendIdleMarkerMessage();
/**
* @param backendIdleMarkerMessage the backendIdleMarkerMessage to set
*/
public void setBackendIdleMarkerMessage(String backendIdleMarkerMessage);
/**
* @return the backendStatisticsLog
*/
public boolean isBackendStatisticsLog();
/**
* @param backendStatisticsLog the backendStatisticsLog to set
*/
public void setBackendStatisticsLog(boolean backendStatisticsLog);
/**
* @return the backendStatisticsLogTime
*/
public int getBackendStatisticsLogTime();
/**
* @param backendStatisticsLogTime the backendStatisticsLogTime to set
*/
public void setBackendStatisticsLogTime(int backendStatisticsLogTime);
/**
* @return the log4jParseConfigResource
*/
public String getLog4jParseConfigResource();
/**
* @param log4jParseConfigResource the log4jParseConfigResource to set
*/
public void setLog4jParseConfigResource(String log4jParseConfigResource);
/**
* @return the log4jAppenderName
*/
public String getLog4jAppenderName();
/**
* @param log4jAppenderName the log4jAppenderName to set
*/
public void setLog4jAppenderName(String log4jAppenderName);
/**
* @return the log4jAppenderAutoAdd
*/
public boolean isLog4jAppenderAutoAdd();
/**
* @param log4jAppenderAutoAdd the log4jAppenderAutoAdd to set
*/
public void setLog4jAppenderAutoAdd(boolean log4jAppenderAutoAdd);
/**
* @return the log4jAppenderAutoAddOnlyOnceError
*/
public boolean isLog4jAppenderAutoAddOnlyOnceError();
/**
* @param log4jAppenderAutoAddOnlyOnceError the log4jAppenderAutoAddOnlyOnceError to set
*/
public void setLog4jAppenderAutoAddOnlyOnceError(boolean log4jAppenderAutoAddOnlyOnceError);
/**
* @return the log4jAppenderToRoot
*/
public boolean isLog4jAppenderToRoot();
/**
* @param log4jAppenderToRoot the log4jAppenderToRoot to set
*/
public void setLog4jAppenderToRoot(boolean log4jAppenderToRoot);
}

View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.2//EN" "jboss-service_4_2.dtd">
<server>
<mbean name="jboss.system:service=Logging,type=DataSourceLogService"
code="net.forwardfire.logstats.jboss.log4j.DataSourceLogService"
interface="net.forwardfire.logstats.jboss.log4j.DataSourceLogServiceMBean">
<attribute name="BackendDataSource">java:DataSourceLogServiceDS</attribute>
<depends>jboss.jca:service=DataSourceBinding,name=DataSourceLogServiceDS</depends>
</mbean>
<!-- Minimal config
<mbean code="net.forwardfire.logstats.jboss.log4j.DataSourceLogService"
name="logging:service=DataSourceLogService,type=Private"
interface="net.forwardfire.logstats.jboss.log4j.DataSourceLogServiceMBean">
<attribute name="BackendDataSource">java:DataSourceLogServiceDS</attribute>
<depends>jboss.jca:service=DataSourceBinding,name=DataSourceLogServiceDS</depends>
</mbean>
-->
<!-- Maximal config
<mbean code="net.forwardfire.logstats.jboss.log4j.DataSourceLogService"
name="logging:service=DataSourceLogService,type=Private"
interface="net.forwardfire.logstats.jboss.log4j.DataSourceLogServiceMBean">
<attribute name="BackendDataSource">java:DataSourceLogServiceDS</attribute>
<attribute name="BackendLogQuery">INSERT INTO log_data (log_date, log_level,hostname, source, message, text_search_vector) VALUES (?,?,?,?,?,to_tsvector('pg_catalog.english',?))</attribute>
<attribute name="BackendLogQueryParameters">time,level,host,source,message,message</attribute>
<attribute name="BackendThreads">5</attribute>
<attribute name="BackendMaxQueueSize">5000</attribute>
<attribute name="BackendHostname">myhost-jboss-extra5</attribute>
<attribute name="BackendKeepAliveTimeout">3600</attribute>
<attribute name="BackendKeepAliveQuery">SELECT 1</attribute>
<attribute name="BackendIdleMarkerTime">10000</attribute>
<attribute name="BackendIdleMarkerMessage">** Mark **</attribute>
<attribute name="BackendStatisticsLog">true</attribute>
<attribute name="BackendStatisticsLogTime">300</attribute>
<attribute name="Log4jParseConfigResource">META-INF/logstats-log4j.xml</attribute>
<attribute name="Log4jAppenderName">LOGSTATS</attribute>
<attribute name="Log4jAppenderAutoAdd">true</attribute>
<attribute name="Log4jAppenderAutoAddOnlyOnceError">true</attribute>
<attribute name="Log4jAppenderToRoot">true</attribute>
<depends>jboss.jca:service=DataSourceBinding,name=DataSourceLogServiceDS</depends>
</mbean>
-->
</server>

View file

@ -0,0 +1,166 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Authors: Chris Taylor, Ceki Gulcu. -->
<!-- Version: 1.2 -->
<!-- A configuration element consists of optional renderer
elements,appender elements, categories and an optional root
element. -->
<!ELEMENT log4j:configuration (renderer*, appender*,(category|logger)*,root?,
categoryFactory?)>
<!-- The "threshold" attribute takes a level value such that all -->
<!-- logging statements with a level equal or below this value are -->
<!-- disabled. -->
<!-- Setting the "debug" enable the printing of internal log4j logging -->
<!-- statements. -->
<!-- By default, debug attribute is "null", meaning that we not do touch -->
<!-- internal log4j logging settings. The "null" value for the threshold -->
<!-- attribute can be misleading. The threshold field of a repository -->
<!-- cannot be set to null. The "null" value for the threshold attribute -->
<!-- simply means don't touch the threshold field, the threshold field -->
<!-- keeps its old value. -->
<!ATTLIST log4j:configuration
xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
threshold (all|debug|info|warn|error|fatal|off|null) "null"
debug (true|false|null) "null"
>
<!-- renderer elements allow the user to customize the conversion of -->
<!-- message objects to String. -->
<!ELEMENT renderer EMPTY>
<!ATTLIST renderer
renderedClass CDATA #REQUIRED
renderingClass CDATA #REQUIRED
>
<!-- Appenders must have a name and a class. -->
<!-- Appenders may contain an error handler, a layout, optional parameters -->
<!-- and filters. They may also reference (or include) other appenders. -->
<!ELEMENT appender (errorHandler?, param*, layout?, filter*, appender-ref*)>
<!ATTLIST appender
name ID #REQUIRED
class CDATA #REQUIRED
>
<!ELEMENT layout (param*)>
<!ATTLIST layout
class CDATA #REQUIRED
>
<!ELEMENT filter (param*)>
<!ATTLIST filter
class CDATA #REQUIRED
>
<!-- ErrorHandlers can be of any class. They can admit any number of -->
<!-- parameters. -->
<!ELEMENT errorHandler (param*, root-ref?, logger-ref*, appender-ref?)>
<!ATTLIST errorHandler
class CDATA #REQUIRED
>
<!ELEMENT root-ref EMPTY>
<!ELEMENT logger-ref EMPTY>
<!ATTLIST logger-ref
ref IDREF #REQUIRED
>
<!ELEMENT param EMPTY>
<!ATTLIST param
name CDATA #REQUIRED
value CDATA #REQUIRED
>
<!-- The priority class is org.apache.log4j.Level by default -->
<!ELEMENT priority (param*)>
<!ATTLIST priority
class CDATA #IMPLIED
value CDATA #REQUIRED
>
<!-- The level class is org.apache.log4j.Level by default -->
<!ELEMENT level (param*)>
<!ATTLIST level
class CDATA #IMPLIED
value CDATA #REQUIRED
>
<!-- If no level element is specified, then the configurator MUST not -->
<!-- touch the level of the named category. -->
<!ELEMENT category (param*,(priority|level)?,appender-ref*)>
<!ATTLIST category
class CDATA #IMPLIED
name CDATA #REQUIRED
additivity (true|false) "true"
>
<!-- If no level element is specified, then the configurator MUST not -->
<!-- touch the level of the named logger. -->
<!ELEMENT logger (level?,appender-ref*)>
<!ATTLIST logger
name ID #REQUIRED
additivity (true|false) "true"
>
<!ELEMENT categoryFactory (param*)>
<!ATTLIST categoryFactory
class CDATA #REQUIRED>
<!ELEMENT appender-ref EMPTY>
<!ATTLIST appender-ref
ref IDREF #REQUIRED
>
<!-- If no priority element is specified, then the configurator MUST not -->
<!-- touch the priority of root. -->
<!-- The root category always exists and cannot be subclassed. -->
<!ELEMENT root (param*, (priority|level)?, appender-ref*)>
<!-- ==================================================================== -->
<!-- A logging event -->
<!-- ==================================================================== -->
<!ELEMENT log4j:eventSet (log4j:event*)>
<!ATTLIST log4j:eventSet
xmlns:log4j CDATA #FIXED "http://jakarta.apache.org/log4j/"
version (1.1|1.2) "1.2"
includesLocationInfo (true|false) "true"
>
<!ELEMENT log4j:event (log4j:message, log4j:NDC?, log4j:throwable?,
log4j:locationInfo?) >
<!-- The timestamp format is application dependent. -->
<!ATTLIST log4j:event
logger CDATA #REQUIRED
level CDATA #REQUIRED
thread CDATA #REQUIRED
timestamp CDATA #REQUIRED
>
<!ELEMENT log4j:message (#PCDATA)>
<!ELEMENT log4j:NDC (#PCDATA)>
<!ELEMENT log4j:throwable (#PCDATA)>
<!ELEMENT log4j:locationInfo EMPTY>
<!ATTLIST log4j:locationInfo
class CDATA #REQUIRED
method CDATA #REQUIRED
file CDATA #REQUIRED
line CDATA #REQUIRED
>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "META-INF/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<!-- Lets create a category so we log ourselfs automaticly -->
<category name="net.forwardfire.logstats.jboss.log4j">
<priority value="DEBUG"/>
<appender-ref ref="LOGSTATS"/>
</category>
<!-- Optinaly add other category here to add appender dynamicly -->
</log4j:configuration>