You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/08/12 14:54:55 UTC
[2/2] jena git commit: Simple logging handler/formatter for use with
pre-formatted messages.
Simple logging handler/formatter for use with pre-formatted messages.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/793ffa1f
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/793ffa1f
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/793ffa1f
Branch: refs/heads/master
Commit: 793ffa1f715fbf3536e554cd5abbce02393eb7b7
Parents: 1ef96bb
Author: Andy Seaborne <an...@apache.org>
Authored: Fri Aug 12 15:50:56 2016 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Fri Aug 12 15:50:56 2016 +0100
----------------------------------------------------------------------
.../jena/atlas/logging/java/FlatFormatter.java | 45 ++++++++++++++++++++
.../jena/atlas/logging/java/FlatHandler.java | 45 ++++++++++++++++++++
2 files changed, 90 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/793ffa1f/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatFormatter.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatFormatter.java b/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatFormatter.java
new file mode 100644
index 0000000..75563e4
--- /dev/null
+++ b/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatFormatter.java
@@ -0,0 +1,45 @@
+/*
+ * 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.jena.atlas.logging.java;
+
+import java.text.MessageFormat ;
+import java.util.logging.Formatter ;
+import java.util.logging.LogRecord ;
+
+/** Very simple formatter - just the log message */
+public class FlatFormatter extends Formatter {
+
+ private final boolean ensureNL ;
+
+ public FlatFormatter() { this(true) ; }
+
+ public FlatFormatter(boolean ensureNewline) {
+ this.ensureNL = ensureNewline ;
+ }
+
+ @Override
+ public String format(LogRecord record) {
+ String message = record.getMessage() ;
+ if ( record.getParameters() != null )
+ message = MessageFormat.format(message, record.getParameters()) ;
+ if ( ensureNL && ! message.endsWith("\n") )
+ message = message + "\n" ;
+ return message ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/793ffa1f/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatHandler.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatHandler.java b/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatHandler.java
new file mode 100644
index 0000000..3216135
--- /dev/null
+++ b/jena-base/src/main/java/org/apache/jena/atlas/logging/java/FlatHandler.java
@@ -0,0 +1,45 @@
+/*
+ * 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.jena.atlas.logging.java;
+
+import java.util.logging.LogRecord ;
+import java.util.logging.StreamHandler ;
+
+/** A handler and formatter for unadorned output to stdout.
+ * Example: NCSA Format logging in Fuseki alerady formats the whole line
+ *
+ * <pre>
+ * org.apache.jena.fuseki.Request.level=INFO
+ * org.apache.jena.fuseki.Request.useParentHandlers=false
+ * org.apache.jena.fuseki.Request.handlers=logging.FlatHandler
+ * </pre>
+ *
+ */
+public class FlatHandler extends StreamHandler {
+
+ public FlatHandler() {
+ super(System.out, new FlatFormatter(true)) ;
+ }
+
+ @Override
+ public void publish(LogRecord record) {
+ super.publish(record);
+ flush();
+ }
+}