You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/28 14:29:46 UTC

svn commit: r769369 - /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Syslog.java

Author: mturk
Date: Tue Apr 28 12:29:46 2009
New Revision: 769369

URL: http://svn.apache.org/viewvc?rev=769369&view=rev
Log:
Add Syslog implementations

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Syslog.java   (with props)

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Syslog.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Syslog.java?rev=769369&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Syslog.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Syslog.java Tue Apr 28 12:29:46 2009
@@ -0,0 +1,102 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 org.apache.commons.runtime.util;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+/**
+ * Native OS System Log support.
+ *
+ * @since Runtime 1.0
+ */
+public class Syslog implements Closeable 
+{
+    private static native void      init0();
+    private static native void      init1(String domain);
+    private static native void      close0()
+        throws IOException, InstantiationException;
+    private static native void      log0(int level, String msg);
+
+    private static boolean isOn = false;
+    private boolean isOwner     = false;
+
+    public Syslog()
+    {
+        if (!isOn) {
+            isOn    = true;
+            isOwner = true;
+            init0();
+        }
+    }
+
+    public Syslog(String domain)
+    {
+        if (!isOn) {
+            isOn    = true;
+            isOwner = true;
+            init1(domain);
+        }
+    }
+
+    /**
+     * Free the allocated resource by the Operating system.
+     *
+     * @see java.io.Closeable#close()
+     * @throws IOException if an I/O error occurs.
+     * @throws InstantiationException if native class loader was not initialized.
+     */
+    public final void close()
+        throws IOException
+    {
+        try {
+            if (isOwner) {
+                isOn = false;
+                close0();
+            }
+        } catch (InstantiationException ex) {
+            // Class is alreay uninitialized.
+            // TODO: We could rethrow IOException here.
+        }
+    }
+
+    /**
+     * Object finalize callback.
+     * Called by the garbage collector on an object when garbage
+     * collection determines that there are no more references to the object.
+     */
+    @Override
+    protected final void finalize()
+        throws Throwable
+    {
+        close();
+    }
+
+    /**
+     * Write the {@code msg} to the system message logger.
+     *
+     * @param level Log level priority.
+     * @param msg The message to log.
+     */
+    public static void log(SyslogLevel level, String msg)
+    {
+        if (isOn) {
+            log0(level.valueOf(), msg);
+        }
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/Syslog.java
------------------------------------------------------------------------------
    svn:eol-style = native