2 * ============LICENSE_START=======================================================
3 * SPARKY (AAI UI service)
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.util;
28 import java.util.List;
30 import org.slf4j.LoggerFactory;
32 import ch.qos.logback.classic.Level;
33 import ch.qos.logback.classic.spi.LoggingEvent;
36 * The Class LogValidator.
38 public class LogValidator {
40 protected CaptureLoggerAppender logger = null;
45 * @param level the level
47 @SuppressWarnings("unchecked")
48 public void initializeLogger(Level level) {
49 ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
50 .getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
51 root.detachAndStopAllAppenders();
52 logger = new CaptureLoggerAppender();
54 root.addAppender(logger);
57 public CaptureLoggerAppender getLogger() {
62 * Dump and count logs.
64 * @param logToConsole the log to console
67 public int dumpAndCountLogs(boolean logToConsole) {
69 List<LoggingEvent> logs = logger.drainAllLogs();
76 for (LoggingEvent e : logs) {
77 System.out.println(e);