Permalink
Browse files

Initial add: syslog module for JBoss AS 7

  • Loading branch information...
1 parent 15b9b43 commit a8dfeba434f7eb993653209f2df999a75841b077 @jbeck123 jbeck123 committed May 13, 2012
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module xmlns="urn:jboss:module:1.1" name="x1.jboss-syslog">
+ <resources>
+ <resource-root path="x1.jboss-syslog-1.0.0.jar"/>
+ </resources>
+ <dependencies>
+
+ </dependencies>
+</module>
View
@@ -0,0 +1,97 @@
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>x1.jboss</groupId>
+ <artifactId>x1.jboss-syslog</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>jboss-syslog</name>
+ <description>Syslog appender for JBoss AS 7</description>
+ <url>http://maven.x1/site/x1/jboss-syslog</url>
+ <inceptionYear>2012</inceptionYear>
+ <scm>
+ <developerConnection>scm:svn:http://www.x1/repos/x1/trunk/x1/jboss-syslog</developerConnection>
+ <url>https://www.x1/cgi-bin/viewvc.cgi/x1/trunk/x1/jboss-syslog</url>
+ </scm>
+ <licenses>
+ <license>
+ <distribution>GNU General Public License, version 2, with the Classpath Exception</distribution>
+ </license>
+ </licenses>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <ciManagement>
+ <system>Hudson</system>
+ <url>http://apollo.x1:9080/job/jboss-syslog/</url>
+ <notifiers>
+ <notifier>
+ <type>mail</type>
+ <sendOnError>true</sendOnError>
+ <sendOnFailure>true</sendOnFailure>
+ <sendOnSuccess>true</sendOnSuccess>
+ <sendOnWarning>true</sendOnWarning>
+ <configuration>
+ <address>root@www.x1</address>
+ </configuration>
+ </notifier>
+ </notifiers>
+ </ciManagement>
+ <distributionManagement>
+ <site>
+ <id>jboss-syslog.x1.website</id>
+ <name>X1 Website</name>
+ <url>scp://joe@www.x1/var/maven/site/x1/jboss-syslog</url>
+ </site>
+ <repository>
+ <id>x1-repo</id>
+ <name>X1 Maven Repository</name>
+ <url>http://www.x1/nexus/content/repositories/x1-repo</url>
+ </repository>
+ <snapshotRepository>
+ <id>x1-snapshot-repo</id>
+ <name>X1 Maven Snapshot Repository</name>
+ <url>http://www.x1/nexus/content/repositories/x1-snapshot-repo</url>
+ </snapshotRepository>
+ </distributionManagement>
+ <organization>
+ <name>X1</name>
+ <url>https://www.x1</url>
+ </organization>
+ <developers>
+ <developer>
+ <id>joe</id>
+ <name>Johannes Beck</name>
+ <email>mail@johannes-beck.name</email>
+ <url>http://johannes-beck.name</url>
+ <organization>X1</organization>
+ <organizationUrl>https://www.x1</organizationUrl>
+ <roles>
+ <role>Developer</role>
+ </roles>
+ <timezone>+1</timezone>
+ <properties>
+ <skype>johannesbeck</skype>
+ </properties>
+ </developer>
+ </developers>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,60 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * The contents of this file are subject to the terms of the GNU
+ * General Public License Version 2 only ("GPL").
+ * You may not use this file except in compliance with the License. You can
+ * obtain a copy of the License at http://www.gnu.org/licenses/gpl-2.0.html
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * This particular file is designated as subject to the "Classpath"
+ * exception.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright (c) 2009-2010 Oracle and/or its affiliates.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package x1.jboss.syslog;
+
+import java.util.concurrent.locks.AbstractQueuedSynchronizer;
+
+/**
+ * Acts like a CountDownLatch except that it only requires a single signal to
+ * fire. Because a latch is non-exclusive, it uses the shared acquire and
+ * release methods.
+ *
+ * @author Jerome Dochez
+ */
+public class BooleanLatch extends AbstractQueuedSynchronizer {
+ private static final long serialVersionUID = -2380570517815530977L;
+
+ public boolean isSignalled() {
+ return getState() != 0;
+ }
+
+ public int tryAcquireShared(int ignore) {
+ return isSignalled() ? 1 : -1;
+ }
+
+ public boolean tryReleaseShared(int ignore) {
+ setState(1);
+ return true;
+ }
+}
@@ -0,0 +1,113 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * The contents of this file are subject to the terms of the GNU
+ * General Public License Version 2 only ("GPL").
+ * You may not use this file except in compliance with the License. You can
+ * obtain a copy of the License at http://www.gnu.org/licenses/gpl-2.0.html
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * This particular file is designated as subject to the "Classpath"
+ * exception.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright (c) 2009-2010 Oracle and/or its affiliates.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package x1.jboss.syslog;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+/**
+ * Send a message via syslog.
+ *
+ * this code is taken from spy.jar and enhanced User: cmott
+ */
+public class Syslog {
+ public static final int EMERG = 0;
+ public static final int ALERT = 1;
+ public static final int CRIT = 2;
+ public static final int ERR = 3;
+ public static final int WARNING = 4;
+ public static final int NOTICE = 5;
+ public static final int INFO = 6;
+ public static final int DEBUG = 7;
+
+ public static final int KERN = 0;
+ public static final int USER = 8;
+ public static final int MAIL = 16;
+ public static final int DAEMON = 24;
+ public static final int AUTH = 32;
+ public static final int SYSLOG = 40;
+ public static final int LPR = 48;
+ public static final int NEWS = 56;
+ public static final int UUCP = 64;
+ public static final int CRON = 72;
+ public static final int AUTHPRIV = 80;
+ public static final int FTP = 88;
+ public static final int LOCAL0 = 128;
+ public static final int LOCAL1 = 136;
+ public static final int LOCAL2 = 144;
+ public static final int LOCAL3 = 152;
+ public static final int LOCAL4 = 160;
+ public static final int LOCAL5 = 168;
+ public static final int LOCAL6 = 176;
+ public static final int LOCAL7 = 184;
+
+ private static final int PORT = 514;
+
+ private final InetAddress addr;
+ private Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).getParent();
+
+ /**
+ * Log to a particular log host.
+ */
+ public Syslog(String loghost) throws UnknownHostException {
+ addr = InetAddress.getByName(loghost);
+ }
+
+ /**
+ * Send a log message.
+ */
+ public void log(int facility, int level, String msg) {
+ int fl = facility | level;
+
+ String what = "<" + fl + ">" + msg;
+
+ try {
+ DatagramPacket dp = new DatagramPacket(what.getBytes(), what.length(), addr, PORT);
+ DatagramSocket s = new DatagramSocket();
+ s.send(dp);
@cmbntr
cmbntr Nov 8, 2012

if this method throws an exception the socket is not closed and the JVM leaks a FileDescriptor

+ if (!s.isClosed()) {
+ s.close();
+ }
+ } catch (IOException e) {
+ logger.log(Level.WARNING, "Error sending syslog packet", e);
+ }
+ }
+
+}
Oops, something went wrong.

0 comments on commit a8dfeba

Please sign in to comment.