Author: carnold
Date: Mon Oct 29 15:55:59 2007
New Revision: 589900
URL: http://svn.apache.org/viewvc?rev=589900&view=rev
Log:
LOGCXX-200: Compression for RollingFileAppender
Added:
logging/log4cxx/trunk/src/main/cpp/gzcompressaction.cpp
logging/log4cxx/trunk/src/main/cpp/zipcompressaction.cpp
logging/log4cxx/trunk/src/main/include/log4cxx/rolling/gzcompressaction.h
logging/log4cxx/trunk/src/main/include/log4cxx/rolling/zipcompressaction.h
logging/log4cxx/trunk/src/test/resources/witness/rolling/sbr-test3.0.gz
- copied unchanged from r566217,
logging/log4j/branches/BRANCH_1_3_ABANDONED/tests/witness/rolling/sbr-test3.0.gz
logging/log4cxx/trunk/src/test/resources/witness/rolling/sbr-test3.1.gz
- copied unchanged from r566217,
logging/log4j/branches/BRANCH_1_3_ABANDONED/tests/witness/rolling/sbr-test3.1.gz
Modified:
logging/log4cxx/trunk/src/main/cpp/Makefile.am
logging/log4cxx/trunk/src/main/cpp/fixedwindowrollingpolicy.cpp
logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp
logging/log4cxx/trunk/src/main/cpp/timebasedrollingpolicy.cpp
logging/log4cxx/trunk/src/test/cpp/rolling/manualrollingtest.cpp
logging/log4cxx/trunk/src/test/cpp/rolling/sizebasedrollingtest.cpp
logging/log4cxx/trunk/src/test/cpp/rolling/timebasedrollingtest.cpp
logging/log4cxx/trunk/src/test/cpp/util/compare.cpp
logging/log4cxx/trunk/src/test/cpp/util/compare.h
Modified: logging/log4cxx/trunk/src/main/cpp/Makefile.am
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/Makefile.am?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/Makefile.am (original)
+++ logging/log4cxx/trunk/src/main/cpp/Makefile.am Mon Oct 29 15:55:59 2007
@@ -62,6 +62,7 @@
fixedwindowrollingpolicy.cpp \
formattinginfo.cpp \
fulllocationpatternconverter.cpp \
+ gzcompressaction.cpp \
hierarchy.cpp \
htmllayout.cpp \
inetaddress.cpp \
@@ -164,7 +165,8 @@
writer.cpp \
writerappender.cpp \
xmllayout.cpp\
- xmlsocketappender.cpp
+ xmlsocketappender.cpp \
+ zipcompressaction.cpp
AM_CPPFLAGS = @CPPFLAGS_ODBC@
liblog4cxx_la_LDFLAGS = -version-info @LT_VERSION@ @LIBS_ODBC@ [EMAIL
PROTECTED]@
Modified: logging/log4cxx/trunk/src/main/cpp/fixedwindowrollingpolicy.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/fixedwindowrollingpolicy.cpp?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/fixedwindowrollingpolicy.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/fixedwindowrollingpolicy.cpp Mon Oct 29
15:55:59 2007
@@ -24,6 +24,8 @@
#include <log4cxx/helpers/exception.h>
#include <log4cxx/rolling/rolloverdescription.h>
#include <log4cxx/rolling/filerenameaction.h>
+#include <log4cxx/rolling/gzcompressaction.h>
+#include <log4cxx/rolling/zipcompressaction.h>
#include <log4cxx/pattern/integerpatternconverter.h>
using namespace log4cxx;
@@ -137,22 +139,17 @@
LogString compressedName(renameTo);
ActionPtr compressAction ;
-//
-// TODO
-//
-#if 0
if (StringHelper::endsWith(renameTo, LOG4CXX_STR(".gz"))) {
- renameTo.erase(renameTo.end() - 3);
+ renameTo.resize(renameTo.size() - 3);
compressAction =
new GZCompressAction(
renameTo, compressedName, true);
- } else if (renameTo.endsWith(".zip")) {
- renameTo.erase(renameTo.end() - 4);
+ } else if (StringHelper::endsWith(renameTo, LOG4CXX_STR(".zip"))) {
+ renameTo.resize(renameTo.size() - 4);
compressAction =
new ZipCompressAction(
renameTo, compressedName, true);
}
-#endif
FileRenameActionPtr renameAction =
new FileRenameAction(
Added: logging/log4cxx/trunk/src/main/cpp/gzcompressaction.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/gzcompressaction.cpp?rev=589900&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/gzcompressaction.cpp (added)
+++ logging/log4cxx/trunk/src/main/cpp/gzcompressaction.cpp Mon Oct 29 15:55:59
2007
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+#include <log4cxx/rolling/gzcompressaction.h>
+#include <apr_thread_proc.h>
+#include <log4cxx/helpers/exception.h>
+
+using namespace log4cxx;
+using namespace log4cxx::rolling;
+using namespace log4cxx::helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(GZCompressAction)
+
+GZCompressAction::GZCompressAction(const File& src,
+ const File& dest,
+ bool del)
+ : source(src), destination(dest), deleteSource(del) {
+}
+
+bool GZCompressAction::execute(log4cxx::helpers::Pool& p) const {
+ if (source.exists(p)) {
+ apr_pool_t* pool = reinterpret_cast<apr_pool_t*>(p.getAPRPool());
+ apr_procattr_t* attr;
+ apr_status_t stat = apr_procattr_create(&attr, pool);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ stat = apr_procattr_io_set(attr, APR_NO_PIPE, APR_FULL_BLOCK,
APR_FULL_BLOCK);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ stat = apr_procattr_cmdtype_set(attr, APR_PROGRAM_PATH);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ //
+ // set child process output to destination file
+ //
+ apr_file_t* child_out;
+ apr_int32_t flags = APR_FOPEN_READ | APR_FOPEN_WRITE |
+ APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE;
+ stat = apr_file_open(&child_out, destination.getOSName().c_str(),
+ flags, APR_OS_DEFAULT, pool);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ stat = apr_procattr_child_out_set(attr, child_out, NULL);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ //
+ // redirect the child's error stream to this processes' error stream
+ //
+ apr_file_t* child_err;
+ stat = apr_file_open_stderr(&child_err, pool);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+ stat = apr_procattr_child_err_set(attr, child_err, NULL);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ const char** args = (const char**)
+ apr_palloc(pool, 4 *sizeof(*args));
+ int i = 0;
+ args[i++] = "gzip";
+ args[i++] = "-c";
+ args[i++] = source.getOSName().c_str();
+ args[i++] = NULL;
+
+
+ apr_proc_t pid;
+ stat = apr_proc_create(&pid, "gzip", args, NULL, attr, pool);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ apr_proc_wait(&pid, NULL, NULL, APR_WAIT);
+ stat = apr_file_close(child_out);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ if (deleteSource) {
+ source.deleteFile(p);
+ }
+ return true;
+ }
+ return false;
+}
+
Modified: logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/rollingfileappender.cpp Mon Oct 29
15:55:59 2007
@@ -83,8 +83,10 @@
lastRolloverAsyncAction = rollover1->getAsynchronous();
if (lastRolloverAsyncAction != NULL) {
-// Thread runner = new Thread(lastRolloverAsyncAction);
-// runner.start();
+ //
+ // TODO: compression not asynchronous
+ //
+ lastRolloverAsyncAction->execute(p);
}
}
@@ -172,7 +174,10 @@
if (rollover1->getAsynchronous() != NULL) {
lastRolloverAsyncAction = rollover1->getAsynchronous();
-// new Thread(lastRolloverAsyncAction).start();
+ //
+ // TODO: compression not currently asynchronous
+ //
+ lastRolloverAsyncAction->execute(p);
}
setFile(
@@ -211,7 +216,10 @@
if (rollover1->getAsynchronous() != NULL) {
lastRolloverAsyncAction = rollover1->getAsynchronous();
-// new Thread(lastRolloverAsyncAction).start();
+ //
+ // TODO: compression not asynchronous
+ //
+ lastRolloverAsyncAction->execute(p);
}
}
Modified: logging/log4cxx/trunk/src/main/cpp/timebasedrollingpolicy.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/timebasedrollingpolicy.cpp?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/timebasedrollingpolicy.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/timebasedrollingpolicy.cpp Mon Oct 29
15:55:59 2007
@@ -22,6 +22,8 @@
#include <log4cxx/rolling/filerenameaction.h>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/helpers/exception.h>
+#include <log4cxx/rolling/gzcompressaction.h>
+#include <log4cxx/rolling/zipcompressaction.h>
#ifndef INT64_C
#define INT64_C(x) x ## LL
@@ -156,22 +158,17 @@
nextActiveFile = currentActiveFile;
}
- //
- // TODO:
- //
-#if 0
if (suffixLength == 3) {
compressAction =
new GZCompressAction(
- new File(lastBaseName), new File(lastFileName), true, getLogger());
+ File(lastBaseName), File(lastFileName), true);
}
if (suffixLength == 4) {
compressAction =
new ZipCompressAction(
- new File(lastBaseName), new File(lastFileName), true, getLogger());
+ File(lastBaseName), File(lastFileName), true);
}
-#endif
lastFileName = newFileName;
Added: logging/log4cxx/trunk/src/main/cpp/zipcompressaction.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/zipcompressaction.cpp?rev=589900&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/zipcompressaction.cpp (added)
+++ logging/log4cxx/trunk/src/main/cpp/zipcompressaction.cpp Mon Oct 29
15:55:59 2007
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+#include <log4cxx/rolling/zipcompressaction.h>
+#include <apr_thread_proc.h>
+#include <log4cxx/helpers/exception.h>
+
+using namespace log4cxx;
+using namespace log4cxx::rolling;
+using namespace log4cxx::helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(ZipCompressAction)
+
+ZipCompressAction::ZipCompressAction(const File& src,
+ const File& dest,
+ bool del)
+ : source(src), destination(dest), deleteSource(del) {
+}
+
+bool ZipCompressAction::execute(log4cxx::helpers::Pool& p) const {
+ if (source.exists(p)) {
+ apr_pool_t* pool = reinterpret_cast<apr_pool_t*>(p.getAPRPool());
+ apr_procattr_t* attr;
+ apr_status_t stat = apr_procattr_create(&attr, pool);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ stat = apr_procattr_io_set(attr, APR_NO_PIPE, APR_NO_PIPE,
APR_FULL_BLOCK);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ stat = apr_procattr_cmdtype_set(attr, APR_PROGRAM_PATH);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+
+ //
+ // redirect the child's error stream to this processes' error stream
+ //
+ apr_file_t* child_err;
+ stat = apr_file_open_stderr(&child_err, pool);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+ stat = apr_procattr_child_err_set(attr, child_err, NULL);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ const char** args = (const char**)
+ apr_palloc(pool, 4 *sizeof(*args));
+ int i = 0;
+ args[i++] = "zip";
+ args[i++] = destination.getOSName().c_str();
+ args[i++] = source.getOSName().c_str();
+ args[i++] = NULL;
+
+ if (destination.exists(p)) {
+ destination.deleteFile(p);
+ }
+
+ apr_proc_t pid;
+ stat = apr_proc_create(&pid, "zip", args, NULL, attr, pool);
+ if (stat != APR_SUCCESS) throw IOException(stat);
+
+ apr_proc_wait(&pid, NULL, NULL, APR_WAIT);
+
+ if (deleteSource) {
+ source.deleteFile(p);
+ }
+ return true;
+ }
+ return false;
+}
+
Added: logging/log4cxx/trunk/src/main/include/log4cxx/rolling/gzcompressaction.h
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/rolling/gzcompressaction.h?rev=589900&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/rolling/gzcompressaction.h
(added)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/rolling/gzcompressaction.h
Mon Oct 29 15:55:59 2007
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+#if !defined(_LOG4CXX_ROLLING_GZ_COMPRESS_ACTION_H)
+#define _LOG4CXX_ROLLING_GZ_COMPRESS_ACTION_H
+
+#include <log4cxx/rolling/action.h>
+#include <log4cxx/file.h>
+
+namespace log4cxx {
+ namespace rolling {
+
+
+ class GZCompressAction : public Action {
+ const File source;
+ const File destination;
+ bool deleteSource;
+ public:
+ DECLARE_ABSTRACT_LOG4CXX_OBJECT(GZCompressAction)
+ BEGIN_LOG4CXX_CAST_MAP()
+ LOG4CXX_CAST_ENTRY(GZCompressAction)
+ LOG4CXX_CAST_ENTRY_CHAIN(Action)
+ END_LOG4CXX_CAST_MAP()
+
+ /**
+ * Constructor.
+ */
+ GZCompressAction(const File& source,
+ const File& destination,
+ bool deleteSource);
+
+ /**
+ * Perform action.
+ *
+ * @return true if successful.
+ */
+ virtual bool execute(log4cxx::helpers::Pool& pool) const;
+
+ private:
+ GZCompressAction(const GZCompressAction&);
+ GZCompressAction& operator=(const GZCompressAction&);
+ };
+
+ typedef log4cxx::helpers::ObjectPtrT<GZCompressAction>
GZCompressActionPtr;
+
+ }
+}
+#endif
+
Added:
logging/log4cxx/trunk/src/main/include/log4cxx/rolling/zipcompressaction.h
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/rolling/zipcompressaction.h?rev=589900&view=auto
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/rolling/zipcompressaction.h
(added)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/rolling/zipcompressaction.h
Mon Oct 29 15:55:59 2007
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+#if !defined(_LOG4CXX_ROLLING_ZIP_COMPRESS_ACTION_H)
+#define _LOG4CXX_ROLLING_ZIP_COMPRESS_ACTION_H
+
+#include <log4cxx/rolling/action.h>
+#include <log4cxx/file.h>
+
+namespace log4cxx {
+ namespace rolling {
+
+
+ class ZipCompressAction : public Action {
+ const File source;
+ const File destination;
+ bool deleteSource;
+ public:
+ DECLARE_ABSTRACT_LOG4CXX_OBJECT(ZipCompressAction)
+ BEGIN_LOG4CXX_CAST_MAP()
+ LOG4CXX_CAST_ENTRY(ZipCompressAction)
+ LOG4CXX_CAST_ENTRY_CHAIN(Action)
+ END_LOG4CXX_CAST_MAP()
+
+ /**
+ * Constructor.
+ */
+ ZipCompressAction(const File& source,
+ const File& destination,
+ bool deleteSource);
+
+ /**
+ * Perform action.
+ *
+ * @return true if successful.
+ */
+ virtual bool execute(log4cxx::helpers::Pool& pool) const;
+
+ private:
+ ZipCompressAction(const ZipCompressAction&);
+ ZipCompressAction& operator=(const ZipCompressAction&);
+ };
+
+ typedef log4cxx::helpers::ObjectPtrT<ZipCompressAction>
ZipCompressActionPtr;
+
+ }
+}
+#endif
+
Modified: logging/log4cxx/trunk/src/test/cpp/rolling/manualrollingtest.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/rolling/manualrollingtest.cpp?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/rolling/manualrollingtest.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/rolling/manualrollingtest.cpp Mon Oct 29
15:55:59 2007
@@ -186,8 +186,8 @@
CPPUNIT_ASSERT_EQUAL(true, File("output/manual-test3.1.gz").exists(p));
CPPUNIT_ASSERT_EQUAL(true,
Compare::compare(File("output/manual-test3.log"),
File("witness/rolling/sbr-test3.log")));
- CPPUNIT_ASSERT_EQUAL(true,
Compare::gzCompare(File("output/manual-test3.0.gz"),
File("witness/rolling/sbr-test3.0.gz")));
- CPPUNIT_ASSERT_EQUAL(true,
Compare::gzCompare(File("output/manual-test3.1.gz"),
File("witness/rolling/sbr-test3.1.gz")));
+ CPPUNIT_ASSERT_EQUAL(File("witness/rolling/sbr-test3.0.gz").length(p),
File("output/manual-test3.0.gz").length(p));
+ CPPUNIT_ASSERT_EQUAL(File("witness/rolling/sbr-test3.1.gz").length(p),
File("output/manual-test3.1.gz").length(p));
}
/**
Modified: logging/log4cxx/trunk/src/test/cpp/rolling/sizebasedrollingtest.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/rolling/sizebasedrollingtest.cpp?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/rolling/sizebasedrollingtest.cpp
(original)
+++ logging/log4cxx/trunk/src/test/cpp/rolling/sizebasedrollingtest.cpp Mon Oct
29 15:55:59 2007
@@ -53,10 +53,10 @@
CPPUNIT_TEST_SUITE(SizeBasedRollingTest);
CPPUNIT_TEST(test1);
CPPUNIT_TEST(test2);
-// TODO: Compression not yet implemented
-// CPPUNIT_TEST(test3);
+ CPPUNIT_TEST(test3);
CPPUNIT_TEST(test4);
CPPUNIT_TEST(test5);
+ CPPUNIT_TEST(test6);
CPPUNIT_TEST_SUITE_END();
LoggerPtr root;
@@ -203,8 +203,8 @@
CPPUNIT_ASSERT_EQUAL(true, File("output/sbr-test3.1.gz").exists(p));
CPPUNIT_ASSERT_EQUAL(true, Compare::compare(File("output/sbr-test3.log"),
File("witness/rolling/sbr-test3.log")));
- CPPUNIT_ASSERT_EQUAL(true,
Compare::gzCompare(File("output/sbr-test3.0.gz"),
File("witness/rolling/sbr-test3.0.gz")));
- CPPUNIT_ASSERT_EQUAL(true,
Compare::gzCompare(File("output/sbr-test3.1.gz"),
File("witness/rolling/sbr-test3.1.gz")));
+ CPPUNIT_ASSERT_EQUAL(File("witness/rolling/sbr-test3.0.gz").length(p),
File("output/sbr-test3.0.gz").length(p));
+ CPPUNIT_ASSERT_EQUAL(File("witness/rolling/sbr-test3.1.gz").length(p),
File("output/sbr-test3.1.gz").length(p));
}
/**
@@ -314,6 +314,39 @@
File("witness/rolling/sbr-test4.log")));
}
}
+
+ /**
+ * Same as testBasic but also with GZ compression.
+ */
+ void test6() {
+ PatternLayoutPtr layout = new PatternLayout(LOG4CXX_STR("%m\n"));
+ RollingFileAppenderPtr rfa = new RollingFileAppender();
+ rfa->setAppend(false);
+ rfa->setLayout(layout);
+
+ FixedWindowRollingPolicyPtr fwrp = new FixedWindowRollingPolicy();
+ SizeBasedTriggeringPolicyPtr sbtp = new SizeBasedTriggeringPolicy();
+
+ sbtp->setMaxFileSize(100);
+ fwrp->setMinIndex(0);
+ rfa->setFile(LOG4CXX_STR("output/sbr-test6.log"));
+ fwrp->setFileNamePattern(LOG4CXX_STR("output/sbr-test6.%i.zip"));
+ Pool p;
+ fwrp->activateOptions(p);
+ rfa->setRollingPolicy(fwrp);
+ rfa->setTriggeringPolicy(sbtp);
+ rfa->activateOptions(p);
+ root->addAppender(rfa);
+
+ common(logger, 100);
+
+ CPPUNIT_ASSERT_EQUAL(true, File("output/sbr-test6.log").exists(p));
+ CPPUNIT_ASSERT_EQUAL(true, File("output/sbr-test6.0.zip").exists(p));
+ CPPUNIT_ASSERT_EQUAL(true, File("output/sbr-test6.1.zip").exists(p));
+
+ CPPUNIT_ASSERT_EQUAL(true, Compare::compare(File("output/sbr-test6.log"),
File("witness/rolling/sbr-test3.log")));
+ }
+
};
Modified: logging/log4cxx/trunk/src/test/cpp/rolling/timebasedrollingtest.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/rolling/timebasedrollingtest.cpp?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/rolling/timebasedrollingtest.cpp
(original)
+++ logging/log4cxx/trunk/src/test/cpp/rolling/timebasedrollingtest.cpp Mon Oct
29 15:55:59 2007
@@ -66,8 +66,10 @@
CPPUNIT_TEST_SUITE(TimeBasedRollingTest);
CPPUNIT_TEST(test1);
CPPUNIT_TEST(test2);
+ CPPUNIT_TEST(test3);
CPPUNIT_TEST(test4);
CPPUNIT_TEST(test5);
+ CPPUNIT_TEST(test6);
CPPUNIT_TEST_SUITE_END();
static LoggerPtr logger;
@@ -198,56 +200,53 @@
}
}
-#if 0
/**
* With compression, activeFileName left blank, no stop/restart
*/
- public void test3() throws Exception {
- PatternLayout layout = new PatternLayout("%c{1} - %m%n");
- RollingFileAppender rfa = new RollingFileAppender();
- rfa.setLayout(layout);
-
- String datePattern = "yyyy-MM-dd_HH_mm_ss";
-
- TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
- tbrp.setFileNamePattern("output/test3-%d{" + datePattern + "}.gz");
- tbrp.activateOptions();
- rfa.setRollingPolicy(tbrp);
- rfa.activateOptions();
- logger.addAppender(rfa);
-
- SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
- String[] filenames = new String[4];
-
- Calendar cal = Calendar.getInstance();
-
- for (int i = 0; i < 3; i++) {
- filenames[i] = "output/test3-" + sdf.format(cal.getTime()) + ".gz";
- cal.add(Calendar.SECOND, 1);
- }
+ void test3() {
+ Pool p;
+ PatternLayoutPtr layout = new PatternLayout(LOG4CXX_STR("%c{1} - %m%n"));
+ RollingFileAppenderPtr rfa = new RollingFileAppender();
+ rfa->setAppend(false);
+ rfa->setLayout(layout);
- filenames[3] = "output/test3-" + sdf.format(cal.getTime());
+ LogString datePattern = LOG4CXX_STR("yyyy-MM-dd_HH_mm_ss");
- System.out.println("Waiting until next second and 100 millis.");
- delayUntilNextSecond(100);
- System.out.println("Done waiting.");
+ TimeBasedRollingPolicyPtr tbrp = new TimeBasedRollingPolicy();
+ tbrp->setFileNamePattern(LogString(LOG4CXX_STR("output/test3-%d{")) +
datePattern + LogString(LOG4CXX_STR("}.gz")));
+ tbrp->activateOptions(p);
+ rfa->setRollingPolicy(tbrp);
+ rfa->activateOptions(p);
+ logger->addAppender(rfa);
- for (int i = 0; i < 5; i++) {
- logger.debug("Hello---" + i);
- Thread.sleep(500);
- }
+ DateFormatPtr sdf = new SimpleDateFormat(datePattern);
+ LogString filenames[4];
- for (int i = 0; i < 4; i++) {
- //System.out.println(i + " expected filename [" + filenames[i] + "].");
- }
+ apr_time_t now = apr_time_now();
+ { for (int i = 0; i < 4; i++) {
+ filenames[i] = LOG4CXX_STR("output/test3-");
+ sdf->format(filenames[i], now, p);
+ filenames[i].append(LOG4CXX_STR(".gz"));
+ now += APR_USEC_PER_SEC;
+ } }
- for (int i = 0; i < 3; i++) {
- assertTrue(Compare.gzCompare(filenames[i], "witness/rolling/tbr-test3."
+ i + ".gz"));
- }
+ filenames[3].resize(filenames[3].size() - 3);
- assertTrue(Compare.compare(filenames[3], "witness/rolling/tbr-test3.3"));
+ delayUntilNextSecond(100);
+
+ { for (int i = 0; i < 5; i++) {
+ std::string message("Hello---");
+ StringHelper::toString(i, p, message);
+ LOG4CXX_DEBUG(logger, message);
+ apr_sleep(APR_USEC_PER_SEC/2);
+ } }
+
+ CPPUNIT_ASSERT_EQUAL(true, File(filenames[0]).exists(p));
+ CPPUNIT_ASSERT_EQUAL(true, File(filenames[1]).exists(p));
+ CPPUNIT_ASSERT_EQUAL(true, File(filenames[2]).exists(p));
+
+ CPPUNIT_ASSERT_EQUAL(true, Compare::compare(File(filenames[3]),
File(LOG4CXX_STR("witness/rolling/tbr-test3.3"))));
}
-#endif
/**
* Without compression, activeFileName set, with stop/restart
@@ -369,119 +368,55 @@
}
}
-#if 0
/**
* With compression, activeFileName set, no stop/restart,
*/
- public void test6() throws Exception {
- PatternLayout layout = new PatternLayout("%c{1} - %m%n");
- RollingFileAppender rfa = new RollingFileAppender();
- rfa.setLayout(layout);
-
- String datePattern = "yyyy-MM-dd_HH_mm_ss";
-
- TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
- tbrp.setFileNamePattern("output/test6-%d{" + datePattern + "}.gz");
- tbrp.setActiveFileName("output/test6.log");
- tbrp.activateOptions();
- rfa.setRollingPolicy(tbrp);
- rfa.activateOptions();
- logger.addAppender(rfa);
-
- SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
- String[] filenames = new String[4];
-
- Calendar cal = Calendar.getInstance();
-
- for (int i = 0; i < 3; i++) {
- filenames[i] = "output/test6-" + sdf.format(cal.getTime()) + ".gz";
- cal.add(Calendar.SECOND, 1);
- }
-
- filenames[3] = "output/test6.log";
-
- System.out.println("Waiting until next second and 100 millis.");
- delayUntilNextSecond(100);
- System.out.println("Done waiting.");
-
- for (int i = 0; i < 5; i++) {
- logger.debug("Hello---" + i);
- Thread.sleep(500);
- }
-
- for (int i = 0; i < 4; i++) {
- //System.out.println(i + " expected filename [" + filenames[i] + "].");
- }
-
- for (int i = 0; i < 3; i++) {
- assertTrue(Compare.gzCompare(filenames[i], "witness/rolling/tbr-test6."
+ i + ".gz"));
- }
-
- assertTrue(Compare.compare(filenames[3], "witness/rolling/tbr-test6.3"));
- }
+ void test6() {
+ Pool p;
+ PatternLayoutPtr layout = new PatternLayout(LOG4CXX_STR("%c{1} - %m%n"));
+ RollingFileAppenderPtr rfa = new RollingFileAppender();
+ rfa->setAppend(false);
+ rfa->setLayout(layout);
- public void testWithJoran1() throws Exception {
- JoranConfigurator jc = new JoranConfigurator();
- jc.doConfigure("./input/rolling/time1.xml",
LogManager.getLoggerRepository());
- jc.dumpErrors();
+ LogString datePattern = LOG4CXX_STR("yyyy-MM-dd_HH_mm_ss");
- String datePattern = "yyyy-MM-dd_HH_mm_ss";
+ TimeBasedRollingPolicyPtr tbrp = new TimeBasedRollingPolicy();
+ tbrp->setFileNamePattern(LogString(LOG4CXX_STR("output/test6-%d{")) +
datePattern + LogString(LOG4CXX_STR("}.gz")));
+ rfa->setFile(LOG4CXX_STR("output/test6.log"));
+ tbrp->activateOptions(p);
+ rfa->setRollingPolicy(tbrp);
+ rfa->activateOptions(p);
+ logger->addAppender(rfa);
- SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
- String[] filenames = new String[4];
+ DateFormatPtr sdf = new SimpleDateFormat(datePattern);
+ LogString filenames[4];
- Calendar cal = Calendar.getInstance();
+ apr_time_t now = apr_time_now();
+ { for (int i = 0; i < 3; i++) {
+ filenames[i] = LOG4CXX_STR("output/test6-");
+ sdf->format(filenames[i], now, p);
+ filenames[i].append(LOG4CXX_STR(".gz"));
+ now += APR_USEC_PER_SEC;
+ } }
- for (int i = 0; i < 4; i++) {
- filenames[i] = "output/test1-" + sdf.format(cal.getTime());
- cal.add(Calendar.SECOND, 1);
- }
+ filenames[3] = "output/test6.log";
- System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
- System.out.println("Done waiting.");
-
- for (int i = 0; i < 5; i++) {
- logger.debug("Hello---" + i);
- Thread.sleep(500);
- }
-
- for (int i = 0; i < 4; i++) {
- //System.out.println(i + " expected filename [" + filenames[i] + "].");
- }
-
- for (int i = 0; i < 4; i++) {
- assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test1." +
i));
- }
-
- }
-
- public void XXXtestWithJoran10() throws Exception {
- JoranConfigurator jc = new JoranConfigurator();
- jc.doConfigure("./input/rolling/time2.xml",
LogManager.getLoggerRepository());
- jc.dumpErrors();
-
- String datePattern = "yyyy-MM-dd";
- SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
- String[] filenames = new String[0];
-
- Calendar cal = Calendar.getInstance();
-
- filenames[0] = "output/test1-" + sdf.format(cal.getTime());
-
- for (int i = 0; i < 5; i++) {
- logger.debug("Hello---" + i);
- Thread.sleep(500);
- }
+ { for (int i = 0; i < 5; i++) {
+ std::string message("Hello---");
+ StringHelper::toString(i, p, message);
+ LOG4CXX_DEBUG(logger, message);
+ apr_sleep(APR_USEC_PER_SEC/2);
+ } }
+ CPPUNIT_ASSERT_EQUAL(true, File(filenames[0]).exists(p));
+ CPPUNIT_ASSERT_EQUAL(true, File(filenames[1]).exists(p));
+ CPPUNIT_ASSERT_EQUAL(true, File(filenames[2]).exists(p));
- for (int i = 0; i < 1; i++) {
- assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test10." +
i));
- }
+ CPPUNIT_ASSERT_EQUAL(true, Compare::compare(File(filenames[3]),
File(LOG4CXX_STR("witness/rolling/tbr-test6.3"))));
}
-#endif
void delayUntilNextSecond(int millis) {
apr_time_t now = apr_time_now();
Modified: logging/log4cxx/trunk/src/test/cpp/util/compare.cpp
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/util/compare.cpp?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/util/compare.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/util/compare.cpp Mon Oct 29 15:55:59 2007
@@ -134,12 +134,6 @@
}
}
-bool Compare::gzCompare(const File& /*file1*/, const File& /*file2*/)
-{
- return false;
-}
-
-
void Compare::emit(const std::string& s1) {
std::cout << s1;
}
Modified: logging/log4cxx/trunk/src/test/cpp/util/compare.h
URL:
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/util/compare.h?rev=589900&r1=589899&r2=589900&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/util/compare.h (original)
+++ logging/log4cxx/trunk/src/test/cpp/util/compare.h Mon Oct 29 15:55:59 2007
@@ -30,9 +30,6 @@
static bool compare(const File& file1,
const File& file2);
- static bool gzCompare(const File& file1,
- const File& file2);
-
private:
/// Prints file on the console.
static void outputFile(const File& file,