Exemple #1
0
  protected TestProtocolServer newTestProtocolServer(URI serverId) {
    LoggerContext loggerContext = new LoggerContext();
    loggerContext.putProperty("host", serverId.toString());

    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(loggerContext);
    try {
      configurator.doConfigure(getClass().getResource("/test-logback.xml"));
    } catch (JoranException e) {
      throw new IllegalStateException("Failed to configure logging", e);
    }

    Logging logging = new LogbackService(null, loggerContext);

    ProtocolServerFactory protocolServerFactory =
        new MultiPaxosServerFactory(new ClusterConfiguration("default"), logging);

    ServerIdElectionCredentialsProvider electionCredentialsProvider =
        new ServerIdElectionCredentialsProvider();
    electionCredentialsProvider.listeningAt(serverId);
    TestProtocolServer protocolServer =
        new TestProtocolServer(
            timeoutStrategy,
            protocolServerFactory,
            serverId,
            new InMemoryAcceptorInstanceStore(),
            electionCredentialsProvider);
    protocolServer.addStateTransitionListener(new StateTransitionLogger(logging));
    return protocolServer;
  }
  public void begin(InterpretationContext ic, String name, Attributes attributes) {
    threshold = System.currentTimeMillis();

    // See LOGBACK-527 (the system property is looked up first. Thus, it overrides
    // the equivalent property in the config file. This reversal of scope priority is justified
    // by the use case: the admin trying to chase rogue config file
    String debugAttrib = getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY);
    if (debugAttrib == null) {
      debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR));
    }

    if (OptionHelper.isEmpty(debugAttrib)
        || debugAttrib.equalsIgnoreCase("false")
        || debugAttrib.equalsIgnoreCase("null")) {
      addInfo(INTERNAL_DEBUG_ATTR + " attribute not set");
    } else {
      OnConsoleStatusListener.addNewInstanceToContext(context);
    }

    processScanAttrib(ic, attributes);

    ContextUtil contextUtil = new ContextUtil(context);
    contextUtil.addHostNameAsProperty();

    if (EnvUtil.isGroovyAvailable()) {
      LoggerContext lc = (LoggerContext) context;
      contextUtil.addGroovyPackages(lc.getFrameworkPackages());
    }

    // the context is turbo filter attachable, so it is pushed on top of the
    // stack
    ic.pushObject(getContext());
  }
 @Before
 public void setUp() throws Exception {
   context = new LoggerContext();
   context.setName("test");
   context.start();
   logger = context.getLogger(TurboFilteringInLoggerTest.class);
 }
Exemple #4
0
  public void testAspects() throws Exception {

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);

    // the context was probably already configured by default configuration
    // rules
    lc.reset();

    configurator.doConfigure(getClass().getResource("logback.xml"));

    ListAppender<LoggingEvent> listAppender =
        (ListAppender<LoggingEvent>)
            lc.getLogger(StopWatch.DEFAULT_LOGGER_NAME).getAppender("listAppender");

    ProfiledObject.simpleTestDefaultTagStatic(10);
    assertTrue(
        "Expected tag not found in " + listAppender.list.get(0).getMessage(),
        listAppender.list.get(0).getMessage().indexOf("tag[simpleTestDefaultTagStatic]") >= 0);

    new ProfiledObject().simpleTestUnprofiled(10);
    assertTrue(
        "Expected tag not found in " + listAppender.list.get(1).getMessage(),
        listAppender.list.get(1).getMessage().indexOf("tag[simpleTestUnprofiled]") >= 0);

    assertEquals("Expected two logging events", 2, listAppender.list.size());
  }
  // A few things that need to get set up before regular init().
  @Override
  protected void internalInit() {
    log.debug("Starting CWM Application Internal Init");
    log.debug("Application Class is " + getClass().getName());

    loadAppProperties();

    // If using Logback as the logger, and we have a logConfig property,
    // then read that configuration.
    File logConfig = configuration.getOptionalFile("cwm.logConfig");
    if (logConfig != null && LoggerFactory.getILoggerFactory() instanceof LoggerContext) {
      log.info("Log Configuration: {}", logConfig);
      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

      try {
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        // the context was probably already configured by default configuration rules
        lc.reset();
        configurator.doConfigure(logConfig);
      } catch (JoranException je) {
        je.printStackTrace();
      }
      StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
    }

    loadServices();

    getComponentInstantiationListeners()
        .add(new GuiceComponentInjector(this, getInjectionModuleArray()));

    super.internalInit();
  }
 /**
  * Initialize logback from the given URL.
  *
  * @param url the url pointing to the location of the config file.
  * @throws JoranException if the url points to a non existing location or an error occurs during
  *     the parsing operation.
  */
 public static void initLogging(URL url) throws JoranException {
   LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
   JoranConfigurator configurator = new JoranConfigurator();
   configurator.setContext(loggerContext);
   loggerContext.reset();
   configurator.doConfigure(url);
 }
  public static void load(String location) throws IOException {

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    File externalConfigFile = new File(location);
    if (!externalConfigFile.exists()) {
      throw new IOException(
          "Logback External Conf File Parameter does not reference a file that exists");
    } else {
      if (!externalConfigFile.isFile()) {
        throw new IOException(
            "Logback External Conf File Parameter exists, but does not reference a file");
      } else {
        if (!externalConfigFile.canRead()) {
          throw new IOException(
              "Logback External Conf File exists and is a file, but cannot be read.");
        } else {
          JoranConfigurator configurator = new JoranConfigurator();
          configurator.setContext(lc);
          lc.reset();
          try {
            configurator.doConfigure(location);
          } catch (JoranException e) {
            throw new RuntimeException(e);
          }
          StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
        }
      }
    }
  }
Exemple #8
0
  public static void main(String[] args) {
    LoggerContext loggerContext = new LoggerContext();
    Display display = new Display();
    ResourceUtil.init(display);
    Shell shell = new Shell(display);
    final Tree tree = new Tree(shell, SWT.BORDER);
    Rectangle clientArea = shell.getClientArea();
    tree.setBounds(clientArea.x, clientArea.y, 200, 200);

    LoggerTree loggerTree = new LoggerTree(loggerContext, tree);
    tree.setMenu(TreeMenuBuilder.buildTreeMenu(loggerTree, null));
    loggerTree.update("com.foo.Bar");
    loggerTree.update("com.foo.Bar");

    loggerContext.getLogger("org.apache.struts").setLevel(Level.ERROR);

    loggerTree.update("org.apache.struts.BlahAction");

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  public synchronized void init() {

    if (isInit == true) throw new RuntimeException("LogbackFactory had init~~~");

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
      File externalConfigFile = new File(fileName);
      if (!externalConfigFile.exists()) {

        throw new IOException("logback server file : " + fileName + " not existed!!!");
      }
      if (!externalConfigFile.isFile()) {
        throw new IOException("logback server file : " + fileName + " not file!!!");
      }
      if (!externalConfigFile.canRead()) {
        throw new IOException("logback server file : " + fileName + " can't read!!!");
      }

      JoranConfigurator configurator = new JoranConfigurator();
      configurator.setContext(lc);
      lc.reset();
      configurator.doConfigure(fileName);
      StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

    } catch (final Exception e) {
      e.printStackTrace();
    }

    isInit = true;
  }
 @RequestMapping(value = "/logs", method = RequestMethod.PUT)
 @ResponseStatus(HttpStatus.NO_CONTENT)
 @Timed
 public void changeLevel(@RequestBody LoggerDTO jsonLogger) {
   LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
   context.getLogger(jsonLogger.getName()).setLevel(Level.valueOf(jsonLogger.getLevel()));
 }
 @Test
 public void testLoggingContextReset() {
   addYesFilter();
   assertNotNull(context.getTurboFilterList().get(0));
   context.reset();
   assertEquals(0, context.getTurboFilterList().size());
 }
Exemple #12
0
  public static void enableLogging(boolean enable) {

    // get the context
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    try {

      // create a new configurator
      JoranConfigurator configurator = new JoranConfigurator();

      // set context and reset it
      configurator.setContext(loggerContext);
      loggerContext.reset();

      // if logging should be enabled
      if (enable) {

        // add the correct properties and load the XML file
        loggerContext.putProperty("araraLogName", AraraConstants.LOGNAME);
        configurator.doConfigure(
            AraraLogging.class.getResourceAsStream("/com/github/arara/conf/logback.xml"));
      }

    } catch (JoranException joranException) {
      // do nothing
    }
  }
  /**
   * Initialize log level overrides from debug options.
   *
   * <p>This may only be called during bootstrapping before any custom overrides are set. Your
   * milage may vary if called while the application is running.
   *
   * @throws Exception
   */
  void initializeLogLevelOverrides() throws Exception {
    // reset current overrides
    overriddenLogLevels.clear();

    // add a note to the status manager
    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final StatusManager sm = lc.getStatusManager();
    if (sm != null) {
      sm.add(new InfoStatus("Initializing log level overrides.", this));
    }

    // apply new overrides
    try {
      final Map<String, String> options =
          BootActivator.getInstance().getService(DebugOptions.class).getOptions();
      for (final Entry<String, String> e : options.entrySet()) {
        final String loggerName = getLoggerNameForDebugOption(e.getKey());
        if (loggerName != null) {
          if ((null != e.getValue()) && !"false".equalsIgnoreCase(e.getValue())) {
            setLogLevelOverride(loggerName, "DEBUG");
          }
        }
      }
    } catch (final ServiceNotAvailableException e) {
      // no debug options available (ignore)
    }
  }
 /**
  * Fixes the Chameleon logging configuration to write the logs in the logs/wisdom.log file instead
  * of chameleon.log file.
  *
  * @param basedir the base directory of the chameleon
  */
 private static void fixLoggingSystem(File basedir) {
   ILoggerFactory factory = LoggerFactory.getILoggerFactory();
   if (factory instanceof LoggerContext) {
     // We know that we are using logback from here.
     LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
     ch.qos.logback.classic.Logger logbackLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
     if (logbackLogger == null) {
       return;
     }
     Appender<ILoggingEvent> appender = logbackLogger.getAppender("FILE");
     if (appender instanceof RollingFileAppender) {
       RollingFileAppender<ILoggingEvent> fileAppender =
           (RollingFileAppender<ILoggingEvent>) appender;
       String file = new File(basedir, "logs/wisdom.log").getAbsolutePath();
       fileAppender.stop();
       // Remove the created log directory.
       // We do that afterwards because on Windows the file cannot be deleted while we still have a
       // logger
       // using it.
       FileUtils.deleteQuietly(new File("logs"));
       fileAppender.setFile(file);
       fileAppender.setContext(lc);
       fileAppender.start();
     }
   }
 }
Exemple #15
0
  @Override
  public void contextInitialized(final ServletContextEvent servletContextEvent) {
    final ServletContext sc = servletContextEvent.getServletContext();
    final String logbackConfigLocation = sc.getInitParameter(LOGBACK_CONFIG_LOCATION);
    String filePath = null;
    try {
      final Path configFile = Paths.get(sc.getResource(logbackConfigLocation).toURI());
      filePath = configFile.toAbsolutePath().toString();

      final File rootFolder = new File(sc.getResource("/").getPath());
      final File logFolder = new File(rootFolder.getParentFile().getPath() + "/logs");
      if (!logFolder.exists()) {
        if (!logFolder.mkdirs()) {
          throw new IOException("Cannot create: " + logFolder.getAbsolutePath());
        }
      }
      System.setProperty("log.basepath", logFolder.getAbsolutePath());
      final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
      final JoranConfigurator configurator = new JoranConfigurator();
      configurator.setContext(context);
      context.reset();
      configurator.doConfigure(configFile.toFile());
    } catch (Exception e) {
      System.err.println("Failed to locate logback config file: " + filePath);
      return;
    }
    System.out.println("[INFO] Init logback by the config file:" + filePath);
  }
 private void initLogging(String location) throws JoranException {
   URL url = getResourceURL(location);
   LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
   loggerContext.reset();
   JoranConfigurator configurator = new JoranConfigurator();
   configurator.setContext(loggerContext);
   configurator.doConfigure(url);
 }
Exemple #17
0
  public static void ConfigureLogbackDirectly(Context context) {
    // reset the default context (which may already have been initialized)
    // since we want to reconfigure it
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();

    // final String LOG_DIR = "/sdcard/GPSLogger";
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final String LOG_DIR =
        prefs.getString(
            "gpslogger_folder", Environment.getExternalStorageDirectory() + "/GPSLogger");

    GpsRollingFileAppender<ILoggingEvent> rollingFileAppender =
        new GpsRollingFileAppender<ILoggingEvent>();
    rollingFileAppender.setAppend(true);
    rollingFileAppender.setContext(lc);

    // OPTIONAL: Set an active log file (separate from the rollover files).
    // If rollingPolicy.fileNamePattern already set, you don't need this.
    rollingFileAppender.setFile(LOG_DIR + "/debuglog.txt");
    rollingFileAppender.setLazy(true);

    TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy =
        new TimeBasedRollingPolicy<ILoggingEvent>();
    rollingPolicy.setFileNamePattern(LOG_DIR + "/debuglog.%d.txt");
    rollingPolicy.setMaxHistory(3);
    rollingPolicy.setParent(rollingFileAppender); // parent and context required!
    rollingPolicy.setContext(lc);
    rollingPolicy.start();

    rollingFileAppender.setRollingPolicy(rollingPolicy);

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setPattern("%d{HH:mm:ss} %-5p %class{0}.%method:%L - %m%n");
    encoder.setContext(lc);
    encoder.start();

    rollingFileAppender.setEncoder(encoder);
    rollingFileAppender.start();

    // setup LogcatAppender
    PatternLayoutEncoder encoder2 = new PatternLayoutEncoder();
    encoder2.setContext(lc);
    encoder2.setPattern("%method:%L - %m%n");
    encoder2.start();

    LogcatAppender logcatAppender = new LogcatAppender();
    logcatAppender.setContext(lc);
    logcatAppender.setEncoder(encoder2);
    logcatAppender.start();

    // add the newly created appenders to the root logger;
    // qualify Logger to disambiguate from org.slf4j.Logger
    ch.qos.logback.classic.Logger root =
        (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.addAppender(rollingFileAppender);
    root.addAppender(logcatAppender);
  }
 @RequestMapping(
     value = "/logs",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public List<LoggerDTO> getList() {
   LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
   return context.getLoggerList().stream().map(LoggerDTO::new).collect(Collectors.toList());
 }
 private Logger createLogger(String loggerName) {
   Logger loggerMock = PowerMockito.mock(Logger.class);
   Mockito.when(loggerMock.getName()).thenReturn("MetricLoggerTest");
   LoggerContext loggerContextMock = PowerMockito.mock(LoggerContext.class);
   Mockito.when(loggerContextMock.getLoggerContextRemoteView())
       .thenReturn(PowerMockito.mock(LoggerContextVO.class));
   Mockito.when(loggerMock.getLoggerContext()).thenReturn(loggerContextMock);
   Mockito.when(LoggerFactory.getLogger(loggerName)).thenReturn(loggerMock);
   return loggerMock;
 }
  /**
   * Add an appender to Logback logging framework that will track the types of log messages made.
   */
  @PostConstruct
  public final void addMetricsAppenderToLogback() {
    final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);

    final InstrumentedAppender metrics = new InstrumentedAppender(this.metricRegistry);
    metrics.setContext(root.getLoggerContext());
    metrics.start();
    root.addAppender(metrics);
  }
Exemple #21
0
  private static void initLogging() {
    final File logDir =
        new File(
            System.getProperty(
                "user.home")); // new File("."); //getDir("log", Constants.TEST ?
                               // Context.MODE_WORLD_READABLE : MODE_PRIVATE);
    final File logFile = new File(logDir, "wowdoge.log");

    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

    final PatternLayoutEncoder filePattern = new PatternLayoutEncoder();
    filePattern.setContext(context);
    filePattern.setPattern("%d{HH:mm:ss.SSS} [%thread] %logger{0} - %msg%n");
    filePattern.start();

    final RollingFileAppender<ILoggingEvent> fileAppender =
        new RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(context);
    fileAppender.setFile(logFile.getAbsolutePath());

    final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy =
        new TimeBasedRollingPolicy<ILoggingEvent>();
    rollingPolicy.setContext(context);
    rollingPolicy.setParent(fileAppender);
    rollingPolicy.setFileNamePattern(logDir.getAbsolutePath() + "/wallet.%d.log.gz");
    rollingPolicy.setMaxHistory(7);
    rollingPolicy.start();

    fileAppender.setEncoder(filePattern);
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.start();

    final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
    logcatTagPattern.setContext(context);
    logcatTagPattern.setPattern("%logger{0}");
    logcatTagPattern.start();

    final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder();
    logcatPattern.setContext(context);
    logcatPattern.setPattern("[%thread] %msg%n");
    logcatPattern.start();

    // final LogcatAppender logcatAppender = new LogcatAppender();
    // logcatAppender.setContext(context);
    // logcatAppender.setTagEncoder(logcatTagPattern);
    // logcatAppender.setEncoder(logcatPattern);
    // logcatAppender.start();

    final ch.qos.logback.classic.Logger log = context.getLogger(Logger.ROOT_LOGGER_NAME);
    log.addAppender(fileAppender);
    // log.addAppender(logcatAppender);
    log.setLevel(Level.INFO); // Level.INFO);

    SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
  }
  @Before
  public void fixture() {
    lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();

    listAppender = new DummyLBAppender();
    listAppender.setContext(lc);
    listAppender.start();
    rootLogger = lc.getLogger("root");
    rootLogger.addAppender(listAppender);
  }
  @Override
  protected void startLifecycleStage1() {
    super.startLifecycleStage1();

    // Work-around for http://jira.qos.ch/browse/LOGBACK-730
    final ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
    if (iLoggerFactory instanceof LoggerContext) {
      final LoggerContext lc = (LoggerContext) iLoggerFactory;
      lc.setPackagingDataEnabled(false);
    }
  }
  @Before
  public void setUp() {
    // Silence all log messages from the PMS code that is being tested
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();

    // Initialize the RendererConfiguration
    RendererConfiguration.loadRendererConfigurations();

    mediaInfoParserIsValid = MediaInfoParser.isValid();
  }
Exemple #25
0
  private static void initLogback() throws JoranException {
    String rocketmqHome =
        System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV));

    // 初始化Logback
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(rocketmqHome + "/conf/logback_tools.xml");
  }
Exemple #26
0
  /** Initializes the logger. */
  private static void initLogger() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

    try {
      JoranConfigurator configurator = new JoranConfigurator();
      configurator.setContext(context);
      context.reset();
      configurator.doConfigure(InspectIT.class.getResourceAsStream("/config/logback.xml"));
    } catch (JoranException je) { // NOPMD NOCHK StatusPrinter will handle this NOCHK
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
  }
  @RequestMapping(value = "/rest/logs", method = RequestMethod.GET, produces = "application/json")
  @Timed
  @ApiIgnore
  public List<LoggerDTO> getList() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

    List<LoggerDTO> loggers = new ArrayList<LoggerDTO>();
    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
      loggers.add(new LoggerDTO(logger));
    }
    return loggers;
  }
 @Test
 public void consolePatternCanBeOverridden() throws JoranException {
   JoranConfigurator configurator = new JoranConfigurator();
   LoggerContext context = new LoggerContext();
   configurator.setContext(context);
   configurator.doConfigure(new File("src/test/resources/custom-console-log-pattern.xml"));
   Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("CONSOLE");
   assertThat(appender).isInstanceOf(ConsoleAppender.class);
   Encoder<?> encoder = ((ConsoleAppender<?>) appender).getEncoder();
   assertThat(encoder).isInstanceOf(PatternLayoutEncoder.class);
   assertThat(((PatternLayoutEncoder) encoder).getPattern()).isEqualTo("foo");
 }
  private void initLogging() {
    // We can't log into the wallet specific directories because
    // logging is initialized well before we've selected one.

    final File logDir = getDir("log", MODE_PRIVATE); // Context.MODE_WORLD_READABLE
    final File logFile = new File(logDir, "wallet32.log");

    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

    final PatternLayoutEncoder filePattern = new PatternLayoutEncoder();
    filePattern.setContext(context);
    filePattern.setPattern("%d{HH:mm:ss.SSS} [%thread] %logger{0} - %msg%n");
    filePattern.start();

    final RollingFileAppender<ILoggingEvent> fileAppender =
        new RollingFileAppender<ILoggingEvent>();
    fileAppender.setContext(context);
    fileAppender.setFile(logFile.getAbsolutePath());

    final TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy =
        new TimeBasedRollingPolicy<ILoggingEvent>();
    rollingPolicy.setContext(context);
    rollingPolicy.setParent(fileAppender);
    rollingPolicy.setFileNamePattern(logDir.getAbsolutePath() + "/wallet32.%d.log.gz");
    rollingPolicy.setMaxHistory(7);
    rollingPolicy.start();

    fileAppender.setEncoder(filePattern);
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.start();

    final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder();
    logcatTagPattern.setContext(context);
    logcatTagPattern.setPattern("%logger{0}");
    logcatTagPattern.start();

    final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder();
    logcatPattern.setContext(context);
    logcatPattern.setPattern("[%thread] %msg%n");
    logcatPattern.start();

    final LogcatAppender logcatAppender = new LogcatAppender();
    logcatAppender.setContext(context);
    logcatAppender.setTagEncoder(logcatTagPattern);
    logcatAppender.setEncoder(logcatPattern);
    logcatAppender.start();

    final ch.qos.logback.classic.Logger log = context.getLogger(Logger.ROOT_LOGGER_NAME);
    log.addAppender(fileAppender);
    log.addAppender(logcatAppender);
    log.setLevel(Level.INFO);
  }
 @RequestMapping(
     value = "/logs",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public List<LoggerDTO> getList() {
   LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
   List<LoggerDTO> loggers = new ArrayList<>();
   for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
     loggers.add(new LoggerDTO(logger));
   }
   return loggers;
 }