⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 patternlayouttest.cpp

📁 log4cxx 0.10 unix下编译包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * 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/logger.h>#include <log4cxx/propertyconfigurator.h>#include <log4cxx/mdc.h>#include <log4cxx/patternlayout.h>#include <log4cxx/fileappender.h>#include "util/compare.h"#include "util/transformer.h"#include "util/absolutedateandtimefilter.h"#include "util/iso8601filter.h"#include "util/absolutetimefilter.h"#include "util/relativetimefilter.h"#include "util/controlfilter.h"#include "util/threadfilter.h"#include "util/linenumberfilter.h"#include "util/filenamefilter.h"#include <iostream>#include <log4cxx/helpers/transcoder.h>#include <log4cxx/helpers/pool.h>#include <apr_strings.h>#include <log4cxx/helpers/pool.h>#include "testchar.h"#include "logunit.h"#include <log4cxx/spi/loggerrepository.h>#include <log4cxx/helpers/stringhelper.h>#define REGEX_STR(x) x#define PAT0 REGEX_STR("\\[[0-9A-FXx]*]\\ (DEBUG|INFO|WARN|ERROR|FATAL) .* - Message [0-9]\\{1,2\\}")#define PAT1 ISO8601_PAT REGEX_STR(" ") PAT0#define PAT2 ABSOLUTE_DATE_AND_TIME_PAT REGEX_STR(" ") PAT0#define PAT3 ABSOLUTE_TIME_PAT REGEX_STR(" ") PAT0#define PAT4 RELATIVE_TIME_PAT REGEX_STR(" ") PAT0#define PAT5 REGEX_STR("\\[[0-9A-FXx]*]\\ (DEBUG|INFO|WARN|ERROR|FATAL) .* : Message [0-9]\\{1,2\\}")#define PAT6 REGEX_STR("\\[[0-9A-FXx]*]\\ (DEBUG|INFO |WARN |ERROR|FATAL) .*patternlayouttest.cpp\\([0-9]\\{1,4\\}\\): Message [0-9]\\{1,3\\}")#define PAT11a REGEX_STR("^(DEBUG|INFO |WARN |ERROR|FATAL) \\[[0-9A-FXx]*]\\ log4j.PatternLayoutTest: Message [0-9]\\{1,2\\}")#define PAT11b REGEX_STR("^(DEBUG|INFO |WARN |ERROR|FATAL) \\[[0-9A-FXx]*]\\ root: Message [0-9]\\{1,2\\}")#define PAT12 REGEX_STR("^\\[[0-9A-FXx]*]\\ (DEBUG|INFO |WARN |ERROR|FATAL) ")\    REGEX_STR(".*patternlayouttest.cpp([0-9]\\{1,4\\}): ")\    REGEX_STR("Message [0-9]\\{1,2\\}")#define PAT_MDC_1 REGEX_STR("")using namespace log4cxx;using namespace log4cxx::helpers;LOGUNIT_CLASS(PatternLayoutTest){        LOGUNIT_TEST_SUITE(PatternLayoutTest);                LOGUNIT_TEST(test1);                LOGUNIT_TEST(test2);                LOGUNIT_TEST(test3);                LOGUNIT_TEST(test4);                LOGUNIT_TEST(test5);                LOGUNIT_TEST(test6);                LOGUNIT_TEST(test7);                LOGUNIT_TEST(test8);                LOGUNIT_TEST(test9);                LOGUNIT_TEST(test10);                LOGUNIT_TEST(test11);                LOGUNIT_TEST(test12);                LOGUNIT_TEST(testMDC1);                LOGUNIT_TEST(testMDC2);        LOGUNIT_TEST_SUITE_END();        LoggerPtr root;        LoggerPtr logger;public:        void setUp()        {                root = Logger::getRootLogger();                MDC::clear();                logger = Logger::getLogger(LOG4CXX_TEST_STR("java.org.apache.log4j.PatternLayoutTest"));        }        void tearDown()        {                MDC::clear();                root->getLoggerRepository()->resetConfiguration();        }        void test1()        {                PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout1.properties"));                common();                LOGUNIT_ASSERT(Compare::compare(TEMP, LOG4CXX_FILE("witness/patternLayout.1")));        }        void test2()        {                PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout2.properties"));                common();                ControlFilter filter1;                filter1 << PAT1;                ISO8601Filter filter2;                ThreadFilter filter3;                std::vector<Filter *> filters;                filters.push_back(&filter1);                filters.push_back(&filter2);                filters.push_back(&filter3);                try                {                        Transformer::transform(TEMP, FILTERED, filters);                }                catch(UnexpectedFormatException& e)                {                        std::cout << "UnexpectedFormatException :" << e.what() << std::endl;                        throw;                }                LOGUNIT_ASSERT(Compare::compare(FILTERED, LOG4CXX_FILE("witness/patternLayout.2")));        }        void test3()        {                PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout3.properties"));                common();                ControlFilter filter1;                filter1 << PAT1;                ISO8601Filter filter2;                ThreadFilter filter3;                std::vector<Filter *> filters;                filters.push_back(&filter1);                filters.push_back(&filter2);                filters.push_back(&filter3);                try                {                        Transformer::transform(TEMP, FILTERED, filters);                }                catch(UnexpectedFormatException& e)                {                        std::cout << "UnexpectedFormatException :" << e.what() << std::endl;                        throw;                }                LOGUNIT_ASSERT(Compare::compare(FILTERED, LOG4CXX_FILE("witness/patternLayout.3")));        }        // Output format:        // 06 avr. 2002 18:30:58,937 [12345] DEBUG atternLayoutTest - Message 0        void test4()        {                PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout4.properties"));                common();                ControlFilter filter1;                filter1 << PAT2;                AbsoluteDateAndTimeFilter filter2;                ThreadFilter filter3;                std::vector<Filter *> filters;                filters.push_back(&filter1);                filters.push_back(&filter2);                filters.push_back(&filter3);                try                {                        Transformer::transform(TEMP, FILTERED, filters);                }                catch(UnexpectedFormatException& e)                {                        std::cout << "UnexpectedFormatException :" << e.what() << std::endl;                        throw;                }                LOGUNIT_ASSERT(Compare::compare(FILTERED, LOG4CXX_FILE("witness/patternLayout.4")));        }        void test5()        {                PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout5.properties"));                common();                ControlFilter filter1;                filter1 << PAT2;                AbsoluteDateAndTimeFilter filter2;                ThreadFilter filter3;                std::vector<Filter *> filters;                filters.push_back(&filter1);                filters.push_back(&filter2);                filters.push_back(&filter3);                try                {                        Transformer::transform(TEMP, FILTERED, filters);                }                catch(UnexpectedFormatException& e)                {                        std::cout << "UnexpectedFormatException :" << e.what() << std::endl;                        throw;                }                LOGUNIT_ASSERT(Compare::compare(FILTERED, LOG4CXX_FILE("witness/patternLayout.5")));        }        void test6()        {                PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout6.properties"));                common();                ControlFilter filter1;                filter1 << PAT3;                AbsoluteTimeFilter filter2;                ThreadFilter filter3;                std::vector<Filter *> filters;                filters.push_back(&filter1);                filters.push_back(&filter2);                filters.push_back(&filter3);                try                {                        Transformer::transform(TEMP, FILTERED, filters);                }                catch(UnexpectedFormatException& e)                {                        std::cout << "UnexpectedFormatException :" << e.what() << std::endl;                        throw;                }                LOGUNIT_ASSERT(Compare::compare(FILTERED, LOG4CXX_FILE("witness/patternLayout.6")));        }        void test7()        {                PropertyConfigurator::configure(LOG4CXX_FILE("input/patternLayout7.properties"));                common();                ControlFilter filter1;                filter1 << PAT3;                AbsoluteTimeFilter filter2;                ThreadFilter filter3;                std::vector<Filter *> filters;                filters.push_back(&filter1);                filters.push_back(&filter2);                filters.push_back(&filter3);                try                {                        Transformer::transform(TEMP, FILTERED, filters);                }                catch(UnexpectedFormatException& e)                {                        std::cout << "UnexpectedFormatException :" << e.what() << std::endl;                        throw;                }                LOGUNIT_ASSERT(Compare::compare(FILTERED, LOG4CXX_FILE("witness/patternLayout.7")));        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -