You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ie...@apache.org on 2013/02/27 09:36:44 UTC
svn commit: r1450675 [2/3] - in /sling/whiteboard/ieb/log: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/sling/ src/main/java/org/apache/sling/commons/
src/main/java/org/apache/sling/commons/log/...
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,379 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * The <code>ScheduledFileRotator</code> is a {@link FileRotator} which rotates
+ * the log file as soon as some configurable time schedule has been passed. Old
+ * log files are renamed after the time period that just passed by. No old log
+ * files are ever removed by this file rotator.
+ * <p>
+ * This file rotator implements the same functionality as the
+ * <code>DailyFileAppender</code> of the Log4J framework.
+ * <p>
+ * Code copied and adapted from
+ * http://svn.apache.org/repos/asf/logging/log4j/tags/v1_2_15/src
+ * /main/java/org/apache/log4j/DailyRollingFileAppender.java from where the
+ * following JavaDoc is also copied.
+ * <p>
+ * The rolling schedule is specified by the <b>datePattern</b> constructor
+ * argument. This pattern should follow the {@link SimpleDateFormat}
+ * conventions. In particular, you <em>must</em> escape literal text within a
+ * pair of single quotes. A formatted version of the date pattern is used as the
+ * suffix for the rolled file name.
+ * <p>
+ * For example, if the log file is configured as <code>/foo/bar.log</code> and
+ * the <b>datePattern</b> set to <code>'.'yyyy-MM-dd</code>, on 2001-02-16 at
+ * midnight, the logging file <code>/foo/bar.log</code> will be copied to
+ * <code>/foo/bar.log.2001-02-16</code> and logging for 2001-02-17 will continue
+ * in <code>/foo/bar.log</code> until it rolls over the next day.
+ * <p>
+ * Is is possible to specify monthly, weekly, half-daily, daily, hourly, or
+ * minutely rollover schedules.
+ * <p>
+ * <table border="1" cellpadding="2">
+ * <tr>
+ * <th>DatePattern</th>
+ * <th>Rollover schedule</th>
+ * <th>Example</th>
+ * <tr>
+ * <td><code>'.'yyyy-MM</code></td>
+ * <td>Rollover at the beginning of each month</td>
+ * <td>At midnight of May 31st, 2002 <code>/foo/bar.log</code> will be copied to
+ * <code>/foo/bar.log.2002-05</code>. Logging for the month of June will be
+ * output to <code>/foo/bar.log</code> until it is also rolled over the next
+ * month.</td>
+ * </tr>
+ * <tr>
+ * <td><code>'.'yyyy-ww</code></td>
+ * <td>Rollover at the first day of each week. The first day of the week depends
+ * on the locale.</td>
+ * <td>Assuming the first day of the week is Sunday, on Saturday midnight, June
+ * 9th 2002, the file <i>/foo/bar.log</i> will be copied to
+ * <i>/foo/bar.log.2002-23</i>. Logging for the 24th week of 2002 will be output
+ * to <code>/foo/bar.log</code> until it is rolled over the next week.</td>
+ * </tr>
+ * <tr>
+ * <td><code>'.'yyyy-MM-dd</code></td>
+ * <td>Rollover at midnight each day.</td>
+ * <td>At midnight, on March 8th, 2002, <code>/foo/bar.log</code> will be copied
+ * to <code>/foo/bar.log.2002-03-08</code>. Logging for the 9th day of March
+ * will be output to <code>/foo/bar.log</code> until it is rolled over the next
+ * day.</td>
+ * </tr>
+ * <tr>
+ * <td><code>'.'yyyy-MM-dd-a</code></td>
+ * <td>Rollover at midnight and midday of each day.</td>
+ * <td>At noon, on March 9th, 2002, <code>/foo/bar.log</code> will be copied to
+ * <code>/foo/bar.log.2002-03-09-AM</code>. Logging for the afternoon of the 9th
+ * will be output to <code>/foo/bar.log</code> until it is rolled over at
+ * midnight.</td>
+ * </tr>
+ * <tr>
+ * <td><code>'.'yyyy-MM-dd-HH</code></td>
+ * <td>Rollover at the top of every hour.</td>
+ * <td>At approximately 11:00.000 o'clock on March 9th, 2002,
+ * <code>/foo/bar.log</code> will be copied to
+ * <code>/foo/bar.log.2002-03-09-10</code>. Logging for the 11th hour of the 9th
+ * of March will be output to <code>/foo/bar.log</code> until it is rolled over
+ * at the beginning of the next hour.</td>
+ * </tr>
+ * <tr>
+ * <td><code>'.'yyyy-MM-dd-HH-mm</code></td>
+ * <td>Rollover at the beginning of every minute.</td>
+ * <td>At approximately 11:23,000, on March 9th, 2001, <code>/foo/bar.log</code>
+ * will be copied to <code>/foo/bar.log.2001-03-09-10-22</code>. Logging for the
+ * minute of 11:23 (9th of March) will be output to <code>/foo/bar.log</code>
+ * until it is rolled over the next minute.</td>
+ * </tr>
+ * </table>
+ * <p>
+ * Do not use the colon ":" character in anywhere in the <b>DatePattern</b>
+ * option. The text before the colon is interpeted as the protocol specificaion
+ * of a URL which is probably not what you want.
+ */
+final class ScheduledFileRotator implements FileRotator {
+
+ private static final String DEFAULT_DATE_PATTERN = "'.'yyyy-MM-dd";
+
+ // The code assumes that the following constants are in a increasing
+ // sequence.
+ private static final int TOP_OF_TROUBLE = -1;
+
+ private static final int TOP_OF_MINUTE = 0;
+
+ private static final int TOP_OF_HOUR = 1;
+
+ private static final int HALF_DAY = 2;
+
+ private static final int TOP_OF_DAY = 3;
+
+ private static final int TOP_OF_WEEK = 4;
+
+ private static final int TOP_OF_MONTH = 5;
+
+ // The gmtTimeZone is used only in computeCheckPeriod() method.
+ private static final TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT");
+
+ /**
+ * The date pattern. By default, the pattern is set to "'.'yyyy-MM-dd"
+ * meaning daily rollover.
+ */
+ private final String datePattern;
+
+ private final Date now;
+
+ private final SimpleDateFormat sdf;
+
+ private final RollingCalendar rc;
+
+ /**
+ * The log file will be renamed to the value of the scheduledFilename
+ * variable when the next interval is entered. For example, if the rollover
+ * period is one hour, the log file will be renamed to the value of
+ * "scheduledFilename" at the beginning of the next hour. The precise time
+ * when a rollover occurs depends on logging activity.
+ */
+ private String scheduledFilename;
+
+ /**
+ * The next time we estimate a rollover should occur.
+ */
+ private long nextCheck;
+
+
+ /**
+ * Instantiate a <code>DailyRollingFileAppender</code> and open the file
+ * designated by <code>filename</code>. The opened filename will become the
+ * ouput destination for this appender.
+ *
+ * @throws IllegalArgumentException if the <code>datePattern</code> is not a
+ * valid <code>java.text.SimpleDateFormat</code> pattern.
+ */
+ ScheduledFileRotator(final String datePattern) {
+ this.datePattern = (datePattern != null && datePattern.length() > 0)
+ ? datePattern
+ : DEFAULT_DATE_PATTERN;
+
+ final long currentTime = System.currentTimeMillis();
+ final int type = computeCheckPeriod(this.datePattern);
+
+ this.nextCheck = currentTime - 1;
+ this.now = new Date(currentTime);
+ this.sdf = new SimpleDateFormat(this.datePattern);
+ this.rc = new RollingCalendar(type);
+ }
+
+ String getDatePattern() {
+ return datePattern;
+ }
+
+ public boolean isRotationDue(final File file) {
+ if (scheduledFilename == null) {
+ scheduledFilename = sdf.format(new Date(file.lastModified()));
+ }
+
+ final long n = System.currentTimeMillis();
+ if (n >= nextCheck) {
+ now.setTime(n);
+ nextCheck = rc.getNextCheckMillis(now);
+ return true;
+ }
+
+ return false;
+ }
+
+ public void rotate(File file) {
+
+ final String baseFileName = file.getAbsolutePath();
+ final String dateSuffix = sdf.format(now);
+
+ // second level guard against rotating too early because the
+ // isRotationDue method may to eagerly return true, especially
+ // when called the first time
+ if (scheduledFilename.equals(dateSuffix)) {
+ return;
+ }
+
+ final File target = new File(baseFileName + scheduledFilename);
+ if (target.exists()) {
+ target.delete();
+ }
+
+ boolean result = file.renameTo(target);
+ if (result) {
+ // LogLog.debug(fileName + " -> " + scheduledFilename);
+ } else {
+ // LogLog.error("Failed to rename [" + fileName + "] to ["
+ // + scheduledFilename + "].");
+ }
+
+ scheduledFilename = dateSuffix;
+ }
+
+
+ /**
+ * @see org.apache.sling.commons.log.internal.slf4j.FileRotator#getRotatedFiles(java.io.File)
+ */
+ public File[] getRotatedFiles(File file) {
+ final File dir = file.getParentFile();
+ final String baseName = file.getName();
+ final File[] logFiles = dir.listFiles(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ return name.startsWith(baseName);
+ }
+ });
+ return logFiles;
+ }
+
+ // -----------------------------------------------------------------------
+
+ // This method computes the roll over period by looping over the
+ // periods, starting with the shortest, and stopping when the r0 is
+ // different from from r1, where r0 is the epoch formatted according
+ // the datePattern (supplied by the user) and r1 is the
+ // epoch+nextMillis(i) formatted according to datePattern. All date
+ // formatting is done in GMT and not local format because the test
+ // logic is based on comparisons relative to 1970-01-01 00:00:00
+ // GMT (the epoch).
+ private static int computeCheckPeriod(String datePattern) {
+ if (datePattern != null) {
+ final RollingCalendar rollingCalendar = new RollingCalendar(
+ gmtTimeZone, Locale.ENGLISH);
+ final Date epoch = new Date(0);
+ final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
+ datePattern);
+ simpleDateFormat.setTimeZone(gmtTimeZone);
+
+ for (int i = TOP_OF_MINUTE; i <= TOP_OF_MONTH; i++) {
+ // formatting in GMT
+ String r0 = simpleDateFormat.format(epoch);
+ rollingCalendar.setType(i);
+ Date next = new Date(rollingCalendar.getNextCheckMillis(epoch));
+ String r1 = simpleDateFormat.format(next);
+ // System.out.println("Type = "+i+", r0 = "+r0+", r1 = "+r1);
+ if (r0 != null && r1 != null && !r0.equals(r1)) {
+ return i;
+ }
+ }
+ }
+ return TOP_OF_TROUBLE; // Deliberately head for trouble...
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": datePattern" + getDatePattern();
+ }
+
+ /**
+ * RollingCalendar is a helper class to DailyRollingFileAppender. Given a
+ * periodicity type and the current time, it computes the start of the next
+ * interval.
+ */
+ private static class RollingCalendar extends GregorianCalendar {
+ private static final long serialVersionUID = -3560331770601814177L;
+
+ int type = ScheduledFileRotator.TOP_OF_TROUBLE;
+
+ RollingCalendar(int type) {
+ super();
+ setType(type);
+ }
+
+ RollingCalendar(TimeZone tz, Locale locale) {
+ super(tz, locale);
+ }
+
+ void setType(int type) {
+ this.type = type;
+ }
+
+ public long getNextCheckMillis(Date now) {
+ return getNextCheckDate(now).getTime();
+ }
+
+ public Date getNextCheckDate(Date now) {
+ this.setTime(now);
+
+ switch (type) {
+ case ScheduledFileRotator.TOP_OF_MINUTE:
+ this.set(Calendar.SECOND, 0);
+ this.set(Calendar.MILLISECOND, 0);
+ this.add(Calendar.MINUTE, 1);
+ break;
+ case ScheduledFileRotator.TOP_OF_HOUR:
+ this.set(Calendar.MINUTE, 0);
+ this.set(Calendar.SECOND, 0);
+ this.set(Calendar.MILLISECOND, 0);
+ this.add(Calendar.HOUR_OF_DAY, 1);
+ break;
+ case ScheduledFileRotator.HALF_DAY:
+ this.set(Calendar.MINUTE, 0);
+ this.set(Calendar.SECOND, 0);
+ this.set(Calendar.MILLISECOND, 0);
+ int hour = get(Calendar.HOUR_OF_DAY);
+ if (hour < 12) {
+ this.set(Calendar.HOUR_OF_DAY, 12);
+ } else {
+ this.set(Calendar.HOUR_OF_DAY, 0);
+ this.add(Calendar.DAY_OF_MONTH, 1);
+ }
+ break;
+ case ScheduledFileRotator.TOP_OF_DAY:
+ this.set(Calendar.HOUR_OF_DAY, 0);
+ this.set(Calendar.MINUTE, 0);
+ this.set(Calendar.SECOND, 0);
+ this.set(Calendar.MILLISECOND, 0);
+ this.add(Calendar.DATE, 1);
+ break;
+ case ScheduledFileRotator.TOP_OF_WEEK:
+ this.set(Calendar.DAY_OF_WEEK, getFirstDayOfWeek());
+ this.set(Calendar.HOUR_OF_DAY, 0);
+ this.set(Calendar.MINUTE, 0);
+ this.set(Calendar.SECOND, 0);
+ this.set(Calendar.MILLISECOND, 0);
+ this.add(Calendar.WEEK_OF_YEAR, 1);
+ break;
+ case ScheduledFileRotator.TOP_OF_MONTH:
+ this.set(Calendar.DATE, 1);
+ this.set(Calendar.HOUR_OF_DAY, 0);
+ this.set(Calendar.MINUTE, 0);
+ this.set(Calendar.SECOND, 0);
+ this.set(Calendar.MILLISECOND, 0);
+ this.add(Calendar.MONTH, 1);
+ break;
+ default:
+ throw new IllegalStateException("Unknown periodicity type.");
+ }
+ return getTime();
+ }
+
+ }
+
+}
\ No newline at end of file
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/ScheduledFileRotator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,141 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+/**
+ * The <code>SizeLimitedFileRotator</code> is a {@link FileRotator} which
+ * rotates the log file as soon as some configurable log file size has been
+ * reached. Further configuration can specify the number of log file generations
+ * to keep in case of rotation.
+ * <p>
+ * This file rotator implements the same functionality as the
+ * <code>RollingFileAppender</code> of the Log4J framework.
+ */
+final class SizeLimitedFileRotator implements FileRotator {
+
+ /**
+ * The maximum index number of old rotated log files to keep. If this is
+ * zero or negative no old generation log files are kept.
+ */
+ private final int maxIndex;
+
+ /**
+ * The maximum size of the log file after which the current log file is
+ * rolled. This setting is ignored if logging to standard output.
+ */
+ private final long maxSize;
+
+ /**
+ * Creates a new instance of the size limited file rotator.
+ *
+ * @param maxNum The maximum number of generations to keep. If this is zero
+ * or negative, no old log files are kept. Otherwise maxNum old
+ * log files (besides the current log file) are kept.
+ * @param maxSize The maximum size of the file after which it is to be
+ * rotated.
+ */
+ SizeLimitedFileRotator(int maxNum, long maxSize) {
+ this.maxIndex = maxNum - 1;
+ this.maxSize = maxSize;
+ }
+
+ /**
+ * NOT PART OF THE API. Returns the maximum index number of old log file
+ * generations. If this is negative, no log file generations are kept.
+ */
+ int getMaxIndex() {
+ return maxIndex;
+ }
+
+ /**
+ * NOT PART OF THE API. Returns the maximum size of the log file at which
+ * the {@link #isRotationDue(File)} returns <code>true</code>.
+ */
+ long getMaxSize() {
+ return maxSize;
+ }
+
+ /**
+ * Returns <code>true</code> if the <code>file</code>'s size is larger than
+ * the configured size of this rotator.
+ */
+ public boolean isRotationDue(File file) {
+ return file.length() > maxSize;
+ }
+
+ /**
+ * Rotates the given <code>file</code> removing the oldest generation log
+ * file and aging all other generations. The current log file becomes
+ * generation 0.
+ */
+ public void rotate(final File file) {
+ if (maxIndex >= 0) {
+
+ final String baseName = file.getAbsolutePath();
+
+ // remove oldest file
+ File dstFile = new File(baseName + "." + maxIndex);
+ if (dstFile.exists()) {
+ dstFile.delete();
+ }
+
+ // rename next files
+ for (int i = maxIndex - 1; i >= 0; i--) {
+ final File srcFile = new File(baseName + "." + i);
+ if (srcFile.exists()) {
+ srcFile.renameTo(dstFile);
+ }
+ dstFile = srcFile;
+ }
+
+ // rename youngest file
+ file.renameTo(dstFile);
+
+ } else {
+
+ // just remove the old file if we don't keep backups
+ file.delete();
+
+ }
+ }
+
+ /**
+ * @see org.apache.sling.commons.log.internal.slf4j.FileRotator#getRotatedFiles(java.io.File)
+ */
+ public File[] getRotatedFiles(File file) {
+ final File dir = file.getParentFile();
+ final String baseName = file.getName();
+ final File[] logFiles = dir.listFiles(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ return name.startsWith(baseName);
+ }
+ });
+ return logFiles;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": maxSize=" + getMaxSize()
+ + ", generations=" + (getMaxIndex() + 1);
+ }
+}
\ No newline at end of file
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SizeLimitedFileRotator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,134 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * The <code>SlingConfigurationPrinter</code> is an Apache Felix
+ * Web Console plugin to display the currently configured log
+ * files.
+ */
+public class SlingConfigurationPrinter {
+
+ /** The registration. */
+ private static ServiceRegistration registration;
+
+ public static void registerPrinter(BundleContext ctx) {
+ if (registration == null) {
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("felix.webconsole.label", "slinglogs");
+ props.put("felix.webconsole.title", "Log Files");
+ props.put("felix.webconsole.configprinter.modes", "always");
+
+ SlingConfigurationPrinter printer = new SlingConfigurationPrinter();
+ registration = ctx.registerService(SlingConfigurationPrinter.class.getName(),
+ printer, props);
+ }
+ }
+
+ public static void unregisterPrinter() {
+ if (registration != null) {
+ registration.unregister();
+ registration = null;
+ }
+ }
+
+ /**
+ * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+ */
+ public void printConfiguration(PrintWriter printWriter) {
+ final LogConfigManager logConfigManager = LogConfigManager.getInstance();
+ Iterator<SlingLoggerWriter> writers = logConfigManager.getSlingLoggerWriters();
+ while (writers.hasNext()) {
+ final SlingLoggerWriter writer = writers.next();
+ final File file = writer.getFile();
+ if ( file != null ) {
+ printWriter.print("Log file ");
+ printWriter.println(getPath(writer));
+ printWriter.println("--------------------------------------------------");
+ FileReader fr = null;
+ try {
+ fr = new FileReader(file);
+ final char[] buffer = new char[512];
+ int len;
+ while ((len = fr.read(buffer)) != -1 ) {
+ printWriter.write(buffer, 0, len);
+ }
+ } catch (IOException ignore) {
+ // we just ignore this
+ } finally {
+ if ( fr != null ) {
+ try {
+ fr.close();
+ } catch (IOException ignoreCloseException) {}
+ }
+ }
+ printWriter.println();
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.felix.webconsole.AttachmentProvider#getAttachments(java.lang.String)
+ */
+ public URL[] getAttachments(String mode) {
+ // we only provide urls for mode zip
+ if ( "zip".equals(mode) ) {
+ final List<URL> urls = new ArrayList<URL>();
+ final LogConfigManager logConfigManager = LogConfigManager.getInstance();
+ Iterator<SlingLoggerWriter> writers = logConfigManager.getSlingLoggerWriters();
+ while (writers.hasNext()) {
+ final SlingLoggerWriter writer = writers.next();
+ final File[] files = writer.getFileRotator().getRotatedFiles(writer.getFile());
+ if ( files != null ) {
+ for(int i = 0; i < files.length; i++) {
+ try {
+ urls.add(files[i].toURL());
+ } catch (MalformedURLException mue) {
+ // we just ignore this file then
+ }
+ }
+ }
+ }
+ if ( urls.size() > 0 ) {
+ return urls.toArray(new URL[urls.size()]);
+ }
+ }
+ return null;
+ }
+
+ private static String getPath(SlingLoggerWriter writer) {
+ final String path = writer.getPath();
+ return (path != null) ? path : "[stdout]";
+ }
+}
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingConfigurationPrinter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,154 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * The <code>SlingLogPanel</code> is a Felix Web Console plugin to display the
+ * current active log bundle configuration.
+ * <p>
+ * In future revisions of this plugin, the configuration may probably even
+ * be modified through this panel.
+ */
+public class SlingLogPanel extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private final LogConfigManager logConfigManager;
+
+ public SlingLogPanel(final LogConfigManager logConfigManager) {
+ this.logConfigManager = logConfigManager;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException {
+
+ final PrintWriter pw = resp.getWriter();
+ final LogConfigManager logConfigManager = this.logConfigManager;
+
+ final String consoleAppRoot = (String) req.getAttribute("felix.webconsole.appRoot");
+ final String cfgColTitle = (consoleAppRoot == null) ? "PID" : "Configuration";
+
+
+ pw.printf(
+ "<p class='statline'>Log Service Stats: %d categories, %d configuration(s), %d writer(s)</p>%n",
+ logConfigManager.getNumLoggers(),
+ logConfigManager.getNumSlingLoggerConfigs(),
+ logConfigManager.getNumSlingLogWriters());
+
+ pw.println("<div class='table'>");
+
+ pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Logger</div>");
+
+ pw.println("<table class='nicetable ui-widget'>");
+
+ pw.println("<thead class='ui-widget-header'>");
+ pw.println("<tr>");
+ pw.println("<th>Log Level</th>");
+ pw.println("<th>Log File</th>");
+ pw.println("<th>Logger</th>");
+ pw.println("<th>" + cfgColTitle + "</th>");
+ pw.println("</tr>");
+ pw.println("</thead>");
+ pw.println("<tbody class='ui-widget-content'>");
+
+ Iterator<SlingLoggerConfig> loggers = logConfigManager.getSlingLoggerConfigs();
+ while (loggers.hasNext()) {
+ final SlingLoggerConfig logger = loggers.next();
+ pw.println("<tr>");
+ pw.println("<td>" + logger.getLogLevel() + "</td>");
+ pw.println("<td>" + getPath(logger.getLogWriter()) + "</td>");
+
+ pw.println("<td>");
+ String sep = "";
+ for (String cat : logger.getCategories()) {
+ pw.print(sep);
+ pw.println(cat);
+ sep = "<br />";
+ }
+ pw.println("</td>");
+
+ pw.println("<td>" + formatPid(consoleAppRoot, logger.getConfigPid()) + "</td>");
+ pw.println("</tr>");
+ }
+
+ pw.println("</tbody>");
+ pw.println("</table>");
+ pw.println("</div>");
+
+ pw.println("<div class='table'>");
+
+ pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Log Writer</div>");
+
+ pw.println("<table class='nicetable ui-widget'>");
+
+ pw.println("<thead class='ui-widget-header'>");
+ pw.println("<tr>");
+ pw.println("<th>Log File</th>");
+ pw.println("<th>Rotator</th>");
+ pw.println("<th>" + cfgColTitle + "</th>");
+ pw.println("</tr>");
+ pw.println("</thead>");
+ pw.println("<tbody class='ui-widget-content'>");
+
+ Iterator<SlingLoggerWriter> writers = logConfigManager.getSlingLoggerWriters();
+ while (writers.hasNext()) {
+ final SlingLoggerWriter writer = writers.next();
+ pw.println("<tr>");
+ pw.println("<td>" + getPath(writer) + "</td>");
+ pw.println("<td>" + writer.getFileRotator() + "</td>");
+ pw.println("<td>" + formatPid(consoleAppRoot, writer.getConfigurationPID())
+ + "</td>");
+ pw.println("</tr>");
+ }
+
+ pw.println("</tbody>");
+ pw.println("</table>");
+ pw.println("</div>");
+ }
+
+ private static String getPath(SlingLoggerWriter writer) {
+ final String path = writer.getPath();
+ return (path != null) ? path : "[stdout]";
+ }
+
+ private static String formatPid(final String consoleAppRoot,
+ final String pid) {
+ if (pid == null) {
+ return "[implicit]";
+ }
+
+ // no recent web console, so just render the pid as the link
+ if (consoleAppRoot == null) {
+ return "<a href=\"configMgr/" + pid + "\">" + pid + "</a>";
+ }
+
+ // recent web console has app root and hence we can use an image
+ return "<a href=\"configMgr/" + pid + "\"><img src=\"" + consoleAppRoot
+ + "/res/imgs/component_configure.png\" border=\"0\" /></a>";
+ }
+}
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogPanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogger.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogger.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogger.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogger.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,476 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.slf4j.Marker;
+import org.slf4j.helpers.FormattingTuple;
+import org.slf4j.helpers.MessageFormatter;
+import org.slf4j.spi.LocationAwareLogger;
+
+class SlingLogger implements LocationAwareLogger {
+
+ private final String name;
+
+ private SlingLoggerConfig config;
+
+ SlingLogger(String name) {
+ this.name = name;
+ }
+
+ void setLoggerConfig(SlingLoggerConfig config) {
+ this.config = config;
+ }
+
+ // ---------- Actual Loger Entry writing -----------------------------------
+
+ private void log(Marker marker, SlingLoggerLevel level, FormattingTuple msg) {
+ log(marker, null, level, msg.getMessage(), msg.getThrowable());
+ }
+
+ private void log(Marker marker, String fqcn, SlingLoggerLevel level,
+ FormattingTuple msg) {
+ log(marker, fqcn, level, msg.getMessage(), msg.getThrowable());
+ }
+
+ private void log(Marker marker, SlingLoggerLevel level, String msg,
+ Throwable t) {
+ log(marker, null, level, msg, t);
+ }
+
+ private void log(Marker marker, String fqcn, SlingLoggerLevel level,
+ String msg, Throwable t) {
+ StringWriter writer = new StringWriter();
+
+ // create the formatted log line; use a local copy because the field
+ // may be exchanged while we are trying to use it
+ config.formatMessage(writer.getBuffer(), marker, getName(), level, msg,
+ fqcn);
+
+ // marker indicating whether a line terminator is to be written after
+ // the message: If a throwable is given, the stacktrace generator
+ // writes a final line terminator and hence we do need to do it
+ // ourselves
+ boolean needsEOL = true;
+
+ // append stacktrace if throwable is not null
+ if (t != null) {
+ writer.write(' ');
+ PrintWriter pw = new PrintWriter(writer);
+ t.printStackTrace(pw);
+ pw.flush();
+
+ // just flush the output, no EOL needed
+ needsEOL = false;
+ }
+
+ // use a local copy because the field may be exchanged while we are
+ // trying to use it
+ config.printMessage(writer.toString(), needsEOL);
+ }
+
+ // ---------- Logger interface ---------------------------------------------
+
+ public String getName() {
+ return name;
+ }
+
+ public void trace(String msg) {
+ if (isTraceEnabled()) {
+ log(null, SlingLoggerLevel.TRACE, msg, null);
+ }
+ }
+
+ public void trace(String format, Object arg) {
+ if (isTraceEnabled()) {
+ log(null, SlingLoggerLevel.TRACE,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void trace(String format, Object[] argArray) {
+ if (isTraceEnabled()) {
+ log(null, SlingLoggerLevel.TRACE,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void trace(String msg, Throwable t) {
+ if (isTraceEnabled()) {
+ log(null, SlingLoggerLevel.TRACE, msg, t);
+ }
+ }
+
+ public void trace(String format, Object arg1, Object arg2) {
+ if (isTraceEnabled()) {
+ log(null, SlingLoggerLevel.TRACE,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void trace(Marker marker, String msg) {
+ if (isTraceEnabled(marker)) {
+ log(marker, SlingLoggerLevel.TRACE, msg, null);
+ }
+ }
+
+ public void trace(Marker marker, String format, Object arg) {
+ if (isTraceEnabled(marker)) {
+ log(marker, SlingLoggerLevel.TRACE,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void trace(Marker marker, String format, Object[] argArray) {
+ if (isTraceEnabled(marker)) {
+ log(marker, SlingLoggerLevel.TRACE,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void trace(Marker marker, String msg, Throwable t) {
+ if (isTraceEnabled(marker)) {
+ log(marker, SlingLoggerLevel.TRACE, msg, t);
+ }
+ }
+
+ public void trace(Marker marker, String format, Object arg1, Object arg2) {
+ if (isTraceEnabled(marker)) {
+ log(marker, SlingLoggerLevel.TRACE,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void debug(String msg) {
+ if (isDebugEnabled()) {
+ log(null, SlingLoggerLevel.DEBUG, msg, null);
+ }
+ }
+
+ public void debug(String format, Object arg) {
+ if (isDebugEnabled()) {
+ log(null, SlingLoggerLevel.DEBUG,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void debug(String format, Object[] argArray) {
+ if (isDebugEnabled()) {
+ log(null, SlingLoggerLevel.DEBUG,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void debug(String msg, Throwable t) {
+ if (isDebugEnabled()) {
+ log(null, SlingLoggerLevel.DEBUG, msg, t);
+ }
+ }
+
+ public void debug(String format, Object arg1, Object arg2) {
+ if (isDebugEnabled()) {
+ log(null, SlingLoggerLevel.DEBUG,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void debug(Marker marker, String msg) {
+ if (isDebugEnabled(marker)) {
+ log(marker, SlingLoggerLevel.DEBUG, msg, null);
+ }
+ }
+
+ public void debug(Marker marker, String format, Object arg) {
+ if (isDebugEnabled(marker)) {
+ log(marker, SlingLoggerLevel.DEBUG,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void debug(Marker marker, String format, Object[] argArray) {
+ if (isDebugEnabled(marker)) {
+ log(marker, SlingLoggerLevel.DEBUG,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void debug(Marker marker, String msg, Throwable t) {
+ if (isDebugEnabled(marker)) {
+ log(marker, SlingLoggerLevel.DEBUG, msg, t);
+ }
+ }
+
+ public void debug(Marker marker, String format, Object arg1, Object arg2) {
+ if (isDebugEnabled(marker)) {
+ log(marker, SlingLoggerLevel.DEBUG,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void info(String msg) {
+ if (isInfoEnabled()) {
+ log(null, SlingLoggerLevel.INFO, msg, null);
+ }
+ }
+
+ public void info(String format, Object arg) {
+ if (isInfoEnabled()) {
+ log(null, SlingLoggerLevel.INFO,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void info(String format, Object[] argArray) {
+ if (isInfoEnabled()) {
+ log(null, SlingLoggerLevel.INFO,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void info(String msg, Throwable t) {
+ if (isInfoEnabled()) {
+ log(null, SlingLoggerLevel.INFO, msg, t);
+ }
+ }
+
+ public void info(String format, Object arg1, Object arg2) {
+ if (isInfoEnabled()) {
+ log(null, SlingLoggerLevel.INFO,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void info(Marker marker, String msg) {
+ if (isInfoEnabled(marker)) {
+ log(marker, SlingLoggerLevel.INFO, msg, null);
+ }
+ }
+
+ public void info(Marker marker, String format, Object arg) {
+ if (isInfoEnabled(marker)) {
+ log(marker, SlingLoggerLevel.INFO,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void info(Marker marker, String format, Object[] argArray) {
+ if (isInfoEnabled(marker)) {
+ log(marker, SlingLoggerLevel.INFO,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void info(Marker marker, String msg, Throwable t) {
+ if (isInfoEnabled(marker)) {
+ log(marker, SlingLoggerLevel.INFO, msg, t);
+ }
+ }
+
+ public void info(Marker marker, String format, Object arg1, Object arg2) {
+ if (isInfoEnabled(marker)) {
+ log(marker, SlingLoggerLevel.INFO,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void warn(String msg) {
+ if (isWarnEnabled()) {
+ log(null, SlingLoggerLevel.WARN, msg, null);
+ }
+ }
+
+ public void warn(String format, Object arg) {
+ if (isWarnEnabled()) {
+ log(null, SlingLoggerLevel.WARN,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void warn(String format, Object[] argArray) {
+ if (isWarnEnabled()) {
+ log(null, SlingLoggerLevel.WARN,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void warn(String msg, Throwable t) {
+ if (isWarnEnabled()) {
+ log(null, SlingLoggerLevel.WARN, msg, t);
+ }
+ }
+
+ public void warn(String format, Object arg1, Object arg2) {
+ if (isWarnEnabled()) {
+ log(null, SlingLoggerLevel.WARN,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void warn(Marker marker, String msg) {
+ if (isWarnEnabled(marker)) {
+ log(marker, SlingLoggerLevel.WARN, msg, null);
+ }
+ }
+
+ public void warn(Marker marker, String format, Object arg) {
+ if (isWarnEnabled(marker)) {
+ log(marker, SlingLoggerLevel.WARN,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void warn(Marker marker, String format, Object[] argArray) {
+ if (isWarnEnabled(marker)) {
+ log(marker, SlingLoggerLevel.WARN,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void warn(Marker marker, String msg, Throwable t) {
+ if (isWarnEnabled(marker)) {
+ log(marker, SlingLoggerLevel.WARN, msg, t);
+ }
+ }
+
+ public void warn(Marker marker, String format, Object arg1, Object arg2) {
+ if (isWarnEnabled(marker)) {
+ log(marker, SlingLoggerLevel.WARN,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void error(String msg) {
+ if (isErrorEnabled()) {
+ log(null, SlingLoggerLevel.ERROR, msg, null);
+ }
+ }
+
+ public void error(String format, Object arg) {
+ if (isErrorEnabled()) {
+ log(null, SlingLoggerLevel.ERROR,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void error(String format, Object[] argArray) {
+ if (isErrorEnabled()) {
+ log(null, SlingLoggerLevel.ERROR,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void error(String msg, Throwable t) {
+ if (isErrorEnabled()) {
+ log(null, SlingLoggerLevel.ERROR, msg, t);
+ }
+ }
+
+ public void error(String format, Object arg1, Object arg2) {
+ if (isErrorEnabled()) {
+ log(null, SlingLoggerLevel.ERROR,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public void error(Marker marker, String msg) {
+ if (isErrorEnabled(marker)) {
+ log(marker, SlingLoggerLevel.ERROR, msg, null);
+ }
+ }
+
+ public void error(Marker marker, String format, Object arg) {
+ if (isErrorEnabled(marker)) {
+ log(marker, SlingLoggerLevel.ERROR,
+ MessageFormatter.format(format, arg));
+ }
+ }
+
+ public void error(Marker marker, String format, Object[] argArray) {
+ if (isErrorEnabled(marker)) {
+ log(marker, SlingLoggerLevel.ERROR,
+ MessageFormatter.arrayFormat(format, argArray));
+ }
+ }
+
+ public void error(Marker marker, String msg, Throwable t) {
+ if (isErrorEnabled(marker)) {
+ log(marker, SlingLoggerLevel.ERROR, msg, t);
+ }
+ }
+
+ public void error(Marker marker, String format, Object arg1, Object arg2) {
+ if (isErrorEnabled(marker)) {
+ log(marker, SlingLoggerLevel.ERROR,
+ MessageFormatter.format(format, arg1, arg2));
+ }
+ }
+
+ public boolean isTraceEnabled() {
+ return config.isLevel(SlingLoggerLevel.TRACE);
+ }
+
+ public boolean isTraceEnabled(Marker marker) {
+ return config.isLevel(SlingLoggerLevel.TRACE);
+ }
+
+ public boolean isDebugEnabled() {
+ return config.isLevel(SlingLoggerLevel.DEBUG);
+ }
+
+ public boolean isDebugEnabled(Marker marker) {
+ return config.isLevel(SlingLoggerLevel.DEBUG);
+ }
+
+ public boolean isInfoEnabled() {
+ return config.isLevel(SlingLoggerLevel.INFO);
+ }
+
+ public boolean isInfoEnabled(Marker marker) {
+ return config.isLevel(SlingLoggerLevel.INFO);
+ }
+
+ public boolean isWarnEnabled() {
+ return config.isLevel(SlingLoggerLevel.WARN);
+ }
+
+ public boolean isWarnEnabled(Marker marker) {
+ return config.isLevel(SlingLoggerLevel.WARN);
+ }
+
+ public boolean isErrorEnabled() {
+ return config.isLevel(SlingLoggerLevel.ERROR);
+ }
+
+ public boolean isErrorEnabled(Marker marker) {
+ return config.isLevel(SlingLoggerLevel.ERROR);
+ }
+
+ //---------- LocationAwareLogger
+
+ public void log(Marker marker, String fqcn, int level, String message,
+ Object[] argArray, Throwable t) {
+ SlingLoggerLevel slingLevel = SlingLoggerLevel.fromSlf4jLevel(level);
+ if (config.isLevel(slingLevel)) {
+ log(marker, fqcn, slingLevel,
+ MessageFormatter.format(message, argArray, t));
+ }
+ }
+}
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLogger.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerConfig.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerConfig.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerConfig.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerConfig.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,132 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.IOException;
+import java.text.FieldPosition;
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.slf4j.Marker;
+
+/**
+ * The <code>SlingLoggerConfig</code> conveys the logger configuration in
+ * terms of writer used and log level set. The respective instances of this
+ * class are also used for the actual message formatting and writing.
+ */
+class SlingLoggerConfig {
+
+ private String configPid;
+
+ private Set<String> categories;
+
+ private SlingLoggerLevel level;
+
+ private MessageFormat format;
+
+ private SlingLoggerWriter writer;
+
+ SlingLoggerConfig(String pid, String pattern, Set<String> categories,
+ SlingLoggerLevel level, SlingLoggerWriter writer) {
+ this.configPid = pid;
+ configure(pattern, categories, level, writer);
+ }
+
+ void configure(String pattern, Set<String> categories,
+ SlingLoggerLevel level, SlingLoggerWriter writer) {
+ this.format = new MessageFormat(pattern);
+ this.categories = new HashSet<String>(categories);
+ this.level = level;
+ this.writer = writer;
+ }
+
+ String getConfigPid() {
+ return configPid;
+ }
+
+ boolean hasCategory(String category) {
+ return categories.contains(category);
+ }
+
+ Set<String> getCategories() {
+ return categories;
+ }
+
+ SlingLoggerWriter getLogWriter() {
+ return writer;
+ }
+
+ void setLogWriter(SlingLoggerWriter writer) {
+ this.writer = writer;
+ }
+
+ SlingLoggerLevel getLogLevel() {
+ return level;
+ }
+
+ boolean isLevel(SlingLoggerLevel reference) {
+ return level.compareTo(reference) <= 0;
+ }
+
+ void setLogLevel(SlingLoggerLevel level) {
+ this.level = level;
+ }
+
+ void formatMessage(StringBuffer buffer, Marker marker, String name,
+ SlingLoggerLevel level, String msg, String fqcn) {
+ // create the formatted log line; use a local copy because the field
+ // may be exchanged while we are trying to use it
+ MessageFormat myFormat = format;
+ synchronized (myFormat) {
+ myFormat.format(new Object[] { new Date(), marker,
+ Thread.currentThread().getName(), name, level.toString(), msg,
+ fqcn }, buffer, new FieldPosition(0));
+ }
+ }
+
+ void printMessage(String message, boolean needsEOL) {
+ // use a local copy because the field may be exchanged while we are
+ // trying to use it
+ SlingLoggerWriter myOutput = writer;
+ synchronized (myOutput) {
+ try {
+
+ // check whether we have to rotate the log file before
+ // writing to it
+ myOutput.checkRotate();
+
+ myOutput.write(message);
+
+ // write line termination or flush, whatever is needed
+ if (needsEOL) {
+ myOutput.writeln();
+ } else {
+ myOutput.flush();
+ }
+
+ } catch (IOException ioe) {
+ LogConfigManager.internalFailure("Failed logging message: "
+ + message, ioe);
+ }
+ }
+ }
+
+}
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerLevel.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerLevel.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerLevel.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerLevel.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,127 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import org.slf4j.spi.LocationAwareLogger;
+
+public enum SlingLoggerLevel {
+
+ TRACE,
+ DEBUG,
+ INFO,
+ WARN,
+ ERROR;
+
+ /**
+ * Translates SLF4J logging levels into {@link SlingLoggerLevel}
+ *
+ * @param level The SLF4J logging level
+ * @return The matching {@link SlingLoggerLevel}
+ */
+ public static SlingLoggerLevel fromSlf4jLevel(int level) {
+ SlingLoggerLevel slingLevel;
+
+ if (level < LocationAwareLogger.DEBUG_INT) {
+ slingLevel = SlingLoggerLevel.TRACE;
+ } else if (level < LocationAwareLogger.INFO_INT) {
+ slingLevel = SlingLoggerLevel.DEBUG;
+ } else if (level < LocationAwareLogger.WARN_INT) {
+ slingLevel = SlingLoggerLevel.INFO;
+ } else if (level < LocationAwareLogger.ERROR_INT) {
+ slingLevel = SlingLoggerLevel.WARN;
+ } else {
+ slingLevel = SlingLoggerLevel.ERROR;
+ }
+
+ return slingLevel;
+ }
+
+ /**
+ * Converts the given {@code levelString} to a {@link SlingLoggerLevel}
+ * instance or {@code null} of not possible. If the value converted to an
+ * upper case string is one of the {@link SlingLoggerLevel} constant names,
+ * the respective constant is returned. Otherwise the string is converted to
+ * an int (if possible) and the following mapping is applied:
+ * <table>
+ * <tr>
+ * <th>level</th>
+ * <th>SlingLoggerLevel</th>
+ * </tr>
+ * <tr>
+ * <td>0 or 1</td>
+ * <td>{@link #ERROR}</td>
+ * </tr>
+ * <tr>
+ * <td>2</td>
+ * <td>{@link #WARN}</td>
+ * </tr>
+ * <tr>
+ * <td>3</td>
+ * <td>{@link #INFO}</td>
+ * </tr>
+ * <tr>
+ * <td>4</td>
+ * <td>{@link #DEBUG}</td>
+ * </tr>
+ * <tr>
+ * <td>5</td>
+ * <td>{@link #TRACE}</td>
+ * </tr>
+ * </table>
+ * <p>
+ * If the string value is not one of the constant names, or cannot be
+ * converted to a number or the number is not one of the supported values,
+ * {@code null} is returned.
+ *
+ * @param levelString The string value to convert into a
+ * {@code SlingLoggerLevel}
+ * @return The {@link SlingLoggerLevel} instance or {@code null} if the
+ * string value cannot be converted.
+ */
+ public static SlingLoggerLevel fromString(final String levelString) {
+ if (levelString != null && levelString.length() > 0) {
+ try {
+ return SlingLoggerLevel.valueOf(levelString.toUpperCase());
+ } catch (IllegalArgumentException iae) {
+ // ignore
+ }
+
+ try {
+ final int level = Integer.parseInt(levelString);
+ switch (level) {
+ case 0:
+ case 1:
+ return ERROR;
+ case 2:
+ return WARN;
+ case 3:
+ return INFO;
+ case 4:
+ return DEBUG;
+ case 5:
+ return TRACE;
+ }
+ } catch (NumberFormatException nfe) {
+ // ignore
+ }
+ }
+
+ return null;
+ }
+}
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerLevel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,380 @@
+/*
+ * 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.sling.commons.log.internal.slf4j;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * The <code>SlingLoggerWriter</code> abstract the output writing functionality
+ * for the Sling Logging implementation. This class is able to write to log
+ * files and manage log file rotation for these files. Alternatively this class
+ * supports writing to the standard output if no log file name is configured.
+ */
+class SlingLoggerWriter extends Writer {
+
+ private static final long FACTOR_KB = 1024;
+
+ private static final long FACTOR_MB = 1024 * FACTOR_KB;
+
+ private static final long FACTOR_GB = 1024 * FACTOR_MB;
+
+ /**
+ * Regular expression matching a maximum file size specification. This
+ * pattern case-insensitively matches a number and an optional factor
+ * specifier of the forms k, kb, m, mb, g, or gb.
+ */
+ private static final Pattern SIZE_SPEC = Pattern.compile(
+ "([\\d]+)([kmg]b?)?", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * The string to place at the end of a line. This is a platform specific
+ * string set from the <code>line.separator</code> system property.
+ */
+ private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
+ /**
+ * The PID of the configuration from which this instance has been
+ * configured. If this is <code>null</code> this instance is an implicitly
+ * created instance which is not tied to any configuration.
+ */
+ private String configurationPID;
+
+ /**
+ * The actual <code>Writer</code> to which this instance delegates any
+ * message writes.
+ */
+ private Writer delegatee;
+
+ /**
+ * The object on which access to this instance are serialized in
+ * multi-threading environments.
+ */
+ protected final Object lock = new Object();
+
+ /**
+ * The <code>java.io.File</code> of the log or <code>null</code> if this
+ * instance writes to the standard output.
+ */
+ private File file;
+
+ /**
+ * The absolute path to the log file or <code>null</code> if this instance
+ * writes to the standard output.
+ */
+ private String path;
+
+ /**
+ * The {@link #writerLimitChecker} used to in the {@link #checkRotate()}
+ * method to check whether the log file must be rotated.
+ */
+ private FileRotator fileRotator;
+
+ /**
+ * Creates a new instance of this class to be configured from the given
+ * <code>configurationPID</code>. This new instance is not ready until
+ * the {@link #configure(String, int, String)} method is being called.
+ */
+ SlingLoggerWriter(String configurationPID) {
+ this.configurationPID = configurationPID;
+ }
+
+ /**
+ * (Re)configures this instance to log to the given file.
+ *
+ * @param logFileName The name of the file to log to or <code>null</code>
+ * to log to the standard output.
+ * @param fileNum The maximum number of old (rotated) files to keep. This is
+ * ignored if <code>logFileName</code> is <code>null</code>.
+ * @param fileSize The maximum size of the log file before rotating it. This
+ * is ignored if <code>logFileName</code> is <code>null</code>.
+ * @throws IOException May be thrown if the file indicated by
+ * <code>logFileName</code> cannot be opened for writing.
+ */
+ void configure(String logFileName, int fileNum, String fileSize)
+ throws IOException {
+
+ // lock this instance while reconfiguring it
+ synchronized (lock) {
+
+ // change the log file name (if reconfigured)
+ if (logFileName == null || !logFileName.equals(path)) {
+
+ // close the current file
+ close();
+
+ if (logFileName == null) {
+
+ this.path = null;
+ this.file = null;
+
+ } else {
+
+ // make sure the file is absolute and derive the path from
+ // there
+ File file = new File(logFileName);
+ if (!file.isAbsolute()) {
+ file = file.getAbsoluteFile();
+ }
+
+ this.path = file.getAbsolutePath();
+ this.file = file;
+ }
+
+ setDelegatee(createWriter());
+
+ } else {
+
+ // make sure, everything is written
+ flush();
+
+ }
+
+ // assign new rotation values
+ if (this.file != null) {
+ this.fileRotator = createFileRotator(fileNum, fileSize);
+ } else {
+ this.fileRotator = FileRotator.DEFAULT;
+ }
+
+ // check whether the new values cause different rotation
+ checkRotate();
+ }
+ }
+
+ /**
+ * Returns the PID of the configuration configuring this instance. This may
+ * be <code>null</code> if this is an implicitly defined log writer
+ * instance.
+ */
+ String getConfigurationPID() {
+ return configurationPID;
+ }
+
+ /**
+ * Sets the PID of the configuration configuring this instance. This may be
+ * <code>null</code> if the configuration is removed but the writer is still
+ * referred to by any logger configuration.
+ */
+ void setConfigurationPID(String configurationPID) {
+ this.configurationPID = configurationPID;
+ }
+
+ String getPath() {
+ return path;
+ }
+
+ FileRotator getFileRotator() {
+ return fileRotator;
+ }
+
+ File getFile() {
+ return file;
+ }
+
+ // ---------- Writer Overwrite ---------------------------------------------
+
+ @Override
+ public void close() throws IOException {
+ synchronized (lock) {
+ if (delegatee != null) {
+ flush();
+
+ delegatee.close();
+ delegatee = null;
+ }
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ synchronized (lock) {
+ if (delegatee != null) {
+ delegatee.flush();
+ }
+ }
+
+ }
+
+ @Override
+ public void write(int c) throws IOException {
+ synchronized (lock) {
+ if (delegatee != null) {
+ delegatee.write(c);
+ }
+ }
+ }
+
+ @Override
+ public void write(char[] cbuf) throws IOException {
+ synchronized (lock) {
+ if (delegatee != null) {
+ delegatee.write(cbuf);
+ }
+ }
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ synchronized (lock) {
+ if (delegatee != null) {
+ delegatee.write(cbuf, off, len);
+ }
+ }
+ }
+
+ @Override
+ public void write(String str) throws IOException {
+ synchronized (lock) {
+ if (delegatee != null) {
+ delegatee.write(str);
+ }
+ }
+ }
+
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ synchronized (lock) {
+ if (delegatee != null) {
+ delegatee.write(str, off, len);
+ }
+ }
+ }
+
+ public void writeln() throws IOException {
+ synchronized (lock) {
+ write(LINE_SEPARATOR);
+ flush();
+ }
+ }
+
+ // ---------- internal -----------------------------------------------------
+
+ static FileRotator createFileRotator(int fileNum, String maxSizeSpec) {
+ if (maxSizeSpec != null && maxSizeSpec.length() > 0) {
+ Matcher sizeMatcher = SIZE_SPEC.matcher(maxSizeSpec);
+ if (sizeMatcher.matches()) {
+ // group 1 is the base size and is an integer number
+ final long baseSize = Long.parseLong(sizeMatcher.group(1));
+
+ // this will take the final size value
+ final long maxSize;
+
+ // group 2 is optional and is the size spec. If not null it is
+ // at least one character long and the first character is enough
+ // for use to know (the second is of no use here)
+ final String factorString = sizeMatcher.group(2);
+ if (factorString == null) {
+ // no factor define, hence no multiplication
+ maxSize = baseSize;
+ } else {
+ switch (factorString.charAt(0)) {
+ case 'k':
+ case 'K':
+ maxSize = baseSize * FACTOR_KB;
+ break;
+ case 'm':
+ case 'M':
+ maxSize = baseSize * FACTOR_MB;
+ break;
+ case 'g':
+ case 'G':
+ maxSize = baseSize * FACTOR_GB;
+ break;
+ default:
+ // we don't really expect this according to the pattern
+ maxSize = baseSize;
+ }
+ }
+
+ // return a size limited rotator with desired number of generations
+ return new SizeLimitedFileRotator(fileNum, maxSize);
+ }
+ }
+
+ // no file size configuration, check for date form specification
+ try {
+ return new ScheduledFileRotator(maxSizeSpec);
+ } catch (IllegalArgumentException iae) {
+ // illegal SimpleDateFormatPattern, fall back to no rotation
+ // TODO: log this somehow !!!
+ return FileRotator.DEFAULT;
+ }
+ }
+
+ private void setDelegatee(Writer delegatee) {
+ synchronized (lock) {
+ this.delegatee = delegatee;
+ }
+ }
+
+ private Writer getDelegatee() {
+ synchronized (lock) {
+ return delegatee;
+ }
+ }
+
+ void checkRotate() throws IOException {
+ synchronized (lock) {
+ if (fileRotator.isRotationDue(file)) {
+
+ getDelegatee().close();
+
+ fileRotator.rotate(file);
+
+ // create new file
+ setDelegatee(createWriter());
+ }
+ }
+ }
+
+ private Writer createWriter() throws IOException {
+ if ( file != null ) {
+ try {
+ // ensure parent path of the file to create
+ file.getParentFile().mkdirs();
+
+ // open the file in append mode to not overwrite an existing
+ // log file from a previous instance running
+ return new OutputStreamWriter(new FileOutputStream(file, true));
+ } catch ( FileNotFoundException e) {
+ System.out.println("Unable to open "+file.getAbsolutePath()+" due to "+e.getMessage());
+ System.out.println("Defaulting to stdout");
+ } catch ( SecurityException e) {
+ System.out.println("Unable to open "+file.getAbsolutePath()+" due to "+e.getMessage());
+ System.out.println("Defaulting to stdout");
+ }
+ file = null;
+ path = null;
+ }
+
+ return new OutputStreamWriter(System.out) {
+ @Override
+ public void close() {
+ // not really !!
+ }
+ };
+ }
+}
Propchange: sling/whiteboard/ieb/log/src/main/java/org/apache/sling/commons/log/internal/slf4j/SlingLoggerWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticLoggerBinder.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticLoggerBinder.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticLoggerBinder.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,61 @@
+/*
+ * 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.slf4j.impl;
+
+import org.apache.sling.commons.log.internal.slf4j.LogConfigManager;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.spi.LoggerFactoryBinder;
+
+/**
+ * This <code>StaticLoggerBinder</code> class returns the
+ * {@link LogConfigManager} singleton instance as the SLF4J logger factory.
+ */
+public class StaticLoggerBinder implements LoggerFactoryBinder {
+
+ /**
+ * The unique instance of this class.
+ */
+ private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
+
+ /**
+ * Returns the unique instance of this class (replaces direct property
+ * access as of SLF4J 1.6.0)
+ */
+ public static final StaticLoggerBinder getSingleton() {
+ return SINGLETON;
+ }
+
+ /**
+ * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
+ * method should always be the same object
+ */
+ private final ILoggerFactory loggerFactory;
+
+ private StaticLoggerBinder() {
+ loggerFactory = LogConfigManager.getInstance();
+ }
+
+ public ILoggerFactory getLoggerFactory() {
+ return loggerFactory;
+ }
+
+ public String getLoggerFactoryClassStr() {
+ return getLoggerFactory().getClass().getName();
+ }
+}
\ No newline at end of file
Propchange: sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticMarkerBinder.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticMarkerBinder.java?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticMarkerBinder.java (added)
+++ sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticMarkerBinder.java Wed Feb 27 08:36:42 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.slf4j.impl;
+
+import org.slf4j.IMarkerFactory;
+import org.slf4j.helpers.BasicMarkerFactory;
+import org.slf4j.spi.MarkerFactoryBinder;
+
+/**
+ * This <code>StaticMarkerBinder</code> class returns an instance of the SLF4J
+ * <code>BasicMarkerFactory</code> as the marker factory.
+ */
+public class StaticMarkerBinder implements MarkerFactoryBinder {
+
+ /**
+ * The unique instance of this class.
+ */
+ public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
+
+ final IMarkerFactory markerFactory = new BasicMarkerFactory();
+
+ private StaticMarkerBinder() {
+ }
+
+ public IMarkerFactory getMarkerFactory() {
+ return markerFactory;
+ }
+
+ public String getMarkerFactoryClassStr() {
+ return getMarkerFactory().getClass().getName();
+ }
+
+}
\ No newline at end of file
Propchange: sling/whiteboard/ieb/log/src/main/java/org/slf4j/impl/StaticMarkerBinder.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.properties Wed Feb 27 08:36:42 2013
@@ -0,0 +1,69 @@
+#
+# 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.
+#
+
+log.name = Apache Sling Logging Configuration
+log.description = Global configuration setup for the Sling OSGi LogService \
+ implementation. See http://sling.apache.org/site/logging.html for more \
+ detailed documentation and description.
+log.level.name = Log Level
+log.level.description = Root Logger log level setting.
+log.file.name = Log File
+log.file.description = The name and path of the log file. If this is empty, \
+ logging goes to standard output (the console). If this path is relative it \
+ is resolved below ${sling.home}.
+log.file.number.name = Number of Log Files
+log.file.number.description = The number of log files to keep. When the threshold of \
+ the log file reaches the configured maximum (see Log File Threshold), \
+ the log file is copied and a new log file is created. This setting specifies \
+ how many generations (incl. the active log file) should be kept. This is a \
+ positive numeric value. The default value is 5. This property is ignored if \
+ the Log File Threshold property specifies time/date controlled log file \
+ rotation.
+log.file.size.name = Log File Threshold
+log.file.size.description = Controls the rotation of the log file by setting \
+ a maximum file size or a time/date schedule at which to rotate the log file. \
+ A size limit can be specified setting a pure number indicating the number \
+ of bytes or a number with a size indicator KB, MB, or GB (case is ignored). \
+ A time/date schedule can be specified as a java.util.SimpleDateFormat \
+ pattern. The default is "'.'yyyy-MM-dd" (daily log rotation).
+
+log.pattern.name = Message Pattern
+log.pattern.description = Message Pattern for formatting the log messages. \
+ This is a java.text.MessageFormat pattern supporting up to six arguments: \
+ {0} The timestamp of type java.util.Date, {1} the log marker, {2} the name \
+ of the current thread, {3} the name of the logger, {4} the debug level and \
+ {5} the actual debug message. If the log call includes a Throwable, the \
+ stacktrace is just appended to the message.
+
+log.factory.writer.name = Apache Sling Logging Writer Configuration
+log.factory.writer.description = Configure a Logger Writer for Sling Logging. \
+ See http://sling.apache.org/site/logging.html for more detailed documentation \
+ and description.
+
+log.factory.config.name = Apache Sling Logging Logger Configuration
+log.factory.config.description = Configure Loggers with levels, pattern and \
+ destination. See http://sling.apache.org/site/logging.html for more detailed \
+ documentation and description.
+
+log.loggers.name = Logger
+log.loggers.description = The logger names applicable for this logger \
+ configuration. Each logger name applies for any child category unless configured \
+ otherwise. E.g. a logger name of org.apache.sling applies to logger \
+ org.apache.sling.commons unless there is a different configuration for \
+ org.apache.sling.commons.
Propchange: sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.xml?rev=1450675&view=auto
==============================================================================
--- sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.xml (added)
+++ sling/whiteboard/ieb/log/src/main/resources/OSGI-INF/metatype/metatype.xml Wed Feb 27 08:36:42 2013
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<metatype:MetaData
+ xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"
+ localization="metatype">
+
+ <!-- global configuration through the LogManager -->
+ <metatype:OCD id="org.apache.sling.commons.log.LogManager"
+ name="%log.name" description="%log.description">
+ <metatype:AD id="org.apache.sling.commons.log.level"
+ type="String" default="info" name="%log.level.name"
+ description="%log.level.description">
+ <metatype:Option value="trace" label="Trace" />
+ <metatype:Option value="debug" label="Debug" />
+ <metatype:Option value="info" label="Information" />
+ <metatype:Option value="warn" label="Warnings" />
+ <metatype:Option value="error" label="Error" />
+ </metatype:AD>
+ <metatype:AD id="org.apache.sling.commons.log.file"
+ type="String" default="logs/error.log" name="%log.file.name"
+ description="%log.file.description" />
+ <metatype:AD id="org.apache.sling.commons.log.file.number"
+ type="Integer" default="5" name="%log.file.number.name"
+ description="%log.file.number.description" />
+ <metatype:AD id="org.apache.sling.commons.log.file.size"
+ type="String" default="'.'yyyy-MM-dd" name="%log.file.size.name"
+ description="%log.file.size.description" />
+ <metatype:AD id="org.apache.sling.commons.log.pattern"
+ type="String"
+ default="{0\,date\,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"
+ name="%log.pattern.name"
+ description="%log.pattern.description" />
+ </metatype:OCD>
+ <metatype:Designate pid="org.apache.sling.commons.log.LogManager">
+ <metatype:Object
+ ocdref="org.apache.sling.commons.log.LogManager" />
+ </metatype:Designate>
+
+ <!-- LoggerWriter factory configuration -->
+ <metatype:OCD
+ id="org.apache.sling.commons.log.LogManager.factory.writer"
+ name="%log.factory.writer.name"
+ description="%log.factory.writer.description">
+ <metatype:AD id="org.apache.sling.commons.log.file"
+ type="String" default="logs/error.log" name="%log.file.name"
+ description="%log.file.description" />
+ <metatype:AD id="org.apache.sling.commons.log.file.number"
+ type="Integer" default="5" name="%log.file.number.name"
+ description="%log.file.number.description" />
+ <metatype:AD id="org.apache.sling.commons.log.file.size"
+ type="String" default="'.'yyyy-MM-dd" name="%log.file.size.name"
+ description="%log.file.size.description" />
+ </metatype:OCD>
+ <metatype:Designate
+ pid="org.apache.sling.commons.log.LogManager.factory.writer"
+ factoryPid="org.apache.sling.commons.log.LogManager.factory.writer">
+ <metatype:Object
+ ocdref="org.apache.sling.commons.log.LogManager.factory.writer" />
+ </metatype:Designate>
+
+ <!-- LoggerConfig factory configuration -->
+ <metatype:OCD
+ id="org.apache.sling.commons.log.LogManager.factory.config"
+ name="%log.factory.config.name"
+ description="%log.factory.config.description">
+ <metatype:AD id="org.apache.sling.commons.log.level"
+ type="String" default="info" name="%log.level.name"
+ description="%log.level.description">
+ <metatype:Option value="trace" label="Trace" />
+ <metatype:Option value="debug" label="Debug" />
+ <metatype:Option value="info" label="Information" />
+ <metatype:Option value="warn" label="Warnings" />
+ <metatype:Option value="error" label="Error" />
+ </metatype:AD>
+ <metatype:AD id="org.apache.sling.commons.log.file"
+ type="String" default="logs/error.log" name="%log.file.name"
+ description="%log.file.description" />
+ <metatype:AD id="org.apache.sling.commons.log.pattern"
+ type="String"
+ default="{0\,date\,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"
+ name="%log.pattern.name"
+ description="%log.pattern.description" />
+ <metatype:AD id="org.apache.sling.commons.log.names"
+ type="String" name="%log.loggers.name"
+ description="%log.loggers.description"
+ cardinality="2147483647" />
+ </metatype:OCD>
+ <metatype:Designate
+ pid="org.apache.sling.commons.log.LogManager.factory.config"
+ factoryPid="org.apache.sling.commons.log.LogManager.factory.config">
+ <metatype:Object
+ ocdref="org.apache.sling.commons.log.LogManager.factory.config" />
+ </metatype:Designate>
+</metatype:MetaData>