From 9649e0585f6a2ad4130bb248756161b941595194 Mon Sep 17 00:00:00 2001 From: "ho.namkoong" Date: Wed, 5 Dec 2012 16:43:46 +0900 Subject: [PATCH] [Title] Implement Log4j appender and configurator for CLI [Type] [Module] [Priority] [Jira#] [Redmine#] 7571 [Problem] [Cause] [Solution] [TestCase] Change-Id: I6bd2c0c1d5526db9afcce61142d4a50d4280523c --- org.tizen.common/META-INF/MANIFEST.MF | 1 + .../common/util/log/TizenLog4Configurator.java | 54 +++++++++++++++ .../tizen/common/util/log/TizenLog4jAppender.java | 78 ++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java create mode 100644 org.tizen.common/src/org/tizen/common/util/log/TizenLog4jAppender.java diff --git a/org.tizen.common/META-INF/MANIFEST.MF b/org.tizen.common/META-INF/MANIFEST.MF index 2e7a5ab..1b1f517 100755 --- a/org.tizen.common/META-INF/MANIFEST.MF +++ b/org.tizen.common/META-INF/MANIFEST.MF @@ -29,6 +29,7 @@ Export-Package: org.apache.commons.lang3.time, org.apache.commons.lang3.tuple, org.apache.commons.logging, + org.apache.log4j, org.junit, org.junit.experimental, org.junit.experimental.categories, diff --git a/org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java b/org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java new file mode 100644 index 0000000..93ff866 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/log/TizenLog4Configurator.java @@ -0,0 +1,54 @@ +/* + * Common + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Ho Namkoong + * + * Licensed 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. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.common.util.log; + +import java.io.InputStream; +import java.net.URL; + +import org.apache.log4j.Appender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.spi.Configurator; +import org.apache.log4j.spi.LoggerRepository; + +public class TizenLog4Configurator implements Configurator { + + @Override + public void doConfigure(InputStream arg0, LoggerRepository arg1) { + // TODO Auto-generated method stub + } + + @Override + public void doConfigure(URL arg0, LoggerRepository arg1) { + arg1.resetConfiguration(); + Logger rootLogger = arg1.getRootLogger(); + rootLogger.setLevel(Level.WARN); + rootLogger.removeAllAppenders(); + Appender tizenAppender = new TizenLog4jAppender(); + rootLogger.addAppender(tizenAppender); + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/log/TizenLog4jAppender.java b/org.tizen.common/src/org/tizen/common/util/log/TizenLog4jAppender.java new file mode 100644 index 0000000..c492d9a --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/log/TizenLog4jAppender.java @@ -0,0 +1,78 @@ +/* + * Common + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Ho Namkoong + * + * Licensed 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. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.common.util.log; + +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.Level; +import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.spi.ThrowableInformation; + +public class TizenLog4jAppender extends AppenderSkeleton{ + + @Override + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public boolean requiresLayout() { + // TODO Auto-generated method stub + return false; + } + + @Override + protected void append(LoggingEvent arg0) { + int level = arg0.getLevel().toInt(); + ThrowableInformation tI = arg0.getThrowableInformation(); + Throwable t = null; + if(tI != null) { + t = tI.getThrowable(); + } + Object msg = arg0.getMessage(); + String message = msg.toString(); + + switch (level) { + case Level.ERROR_INT: + Logger.error(message, t); + break; + case Level.WARN_INT: + Logger.warning(message, t); + break; + case Level.DEBUG_INT: + Logger.debug(message, t); + break; + case Level.FATAL_INT: + Logger.error(message, t); + break; + case Level.INFO_INT: + Logger.info(message, t); + break; + default: + break; + } + } +} -- 2.7.4