ch.qos.logback.classic.android.LogcatAppender Java Examples
The following examples show how to use
ch.qos.logback.classic.android.LogcatAppender.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogbackConfig.java From g4proxy with Apache License 2.0 | 6 votes |
private static void configLog() { LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); context.reset(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setPattern("g4Proxy-%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); encoder.setContext(context); encoder.start(); LogcatAppender logcatAppender = new LogcatAppender(); logcatAppender.setContext(context); logcatAppender.setEncoder(encoder); logcatAppender.setName("logcat1"); logcatAppender.start(); Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); root.setLevel(Level.INFO); root.addAppender(logcatAppender); }
Example #2
Source File: BaseTestCase.java From AndroidMvc with Apache License 2.0 | 6 votes |
private static void configureLogbackDirectly() { // reset the default context (which may already have been initialized) // since we want to reconfigure it LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.reset(); // setup LogcatAppender PatternLayoutEncoder encoder2 = new PatternLayoutEncoder(); encoder2.setContext(lc); encoder2.setPattern("[%thread] %msg%n"); encoder2.start(); LogcatAppender logcatAppender = new LogcatAppender(); logcatAppender.setContext(lc); logcatAppender.setEncoder(encoder2); logcatAppender.start(); // backup 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(logcatAppender); root.setLevel(Level.ALL); }
Example #3
Source File: MvcApp.java From AndroidMvc with Apache License 2.0 | 4 votes |
private void configureLogbackDirectly() { // reset the default context (which may already have been initialized) // since we want to reconfigure it LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.reset(); // setup FileAppender PatternLayoutEncoder encoder1 = new PatternLayoutEncoder(); encoder1.setContext(lc); encoder1.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); encoder1.start(); FileAppender<ILoggingEvent> fileAppender = new FileAppender<>(); fileAppender.setContext(lc); fileAppender.setFile(this.getFileStreamPath("app.log").getAbsolutePath()); fileAppender.setEncoder(encoder1); fileAppender.start(); // setup LogcatAppender PatternLayoutEncoder encoder2 = new PatternLayoutEncoder(); encoder2.setContext(lc); encoder2.setPattern("[%thread] %msg%n"); encoder2.start(); LogcatAppender logcatAppender = new LogcatAppender(); logcatAppender.setContext(lc); logcatAppender.setEncoder(encoder2); logcatAppender.start(); // backup 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(fileAppender); root.addAppender(logcatAppender); if (BuildConfig.DEBUG) { root.setLevel(Level.ALL); } else { root.setLevel(Level.INFO); } }
Example #4
Source File: BitherApplication.java From bither-android with Apache License 2.0 | 4 votes |
private void initLogging() { final File logDir = getLogDir(); final File logFile = new File(logDir, "bitherj.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() + "/bitherj.%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); }
Example #5
Source File: LoggingHelper.java From rpicheck with MIT License | 4 votes |
/** * Initialize and configure the logback logging. * Java configuration is used to rely on {@link Context#getExternalFilesDir(String)} to provide a storage directory. * This must be called on every "entry-point" to this app, e.g. Widget Configuration screen or MainActivity. * * @param context application context */ public static void initLogging(Context context) { final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); boolean isDebugLogging = sharedPrefs.getBoolean(SettingsActivity.KEY_PREF_DEBUG_LOGGING, false); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.reset(); // 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.setLevel(Level.TRACE); PatternLayoutEncoder encoder1 = new PatternLayoutEncoder(); encoder1.setContext(lc); encoder1.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); encoder1.start(); // setup LogcatAppender PatternLayoutEncoder encoder2 = new PatternLayoutEncoder(); encoder2.setContext(lc); encoder2.setPattern("[%thread] %msg%n"); encoder2.start(); LogcatAppender logcatAppender = new LogcatAppender(); logcatAppender.setContext(lc); logcatAppender.setEncoder(encoder2); logcatAppender.start(); // Log-Level for RaspiCheck ch.qos.logback.classic.Logger rpicheckLogger = (ch.qos.logback.classic.Logger) LoggerFactory .getLogger("de.eidottermihi.rpicheck"); rpicheckLogger.setLevel(isDebugLogging ? Level.DEBUG : Level.INFO); ch.qos.logback.classic.Logger sshjLogger = (ch.qos.logback.classic.Logger) LoggerFactory .getLogger("net.schmizz"); sshjLogger.setLevel(Level.WARN); // setup FileAppender String logPath = getLogfilePath(context); if (logPath != null) { FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>(); fileAppender.setContext(lc); fileAppender.setFile(logPath); fileAppender.setEncoder(encoder1); fileAppender.start(); rpicheckLogger.addAppender(fileAppender); sshjLogger.addAppender(fileAppender); } root.addAppender(logcatAppender); LOGGER.debug("Logging was configured, debug logging enabled: {}", isDebugLogging); }
Example #6
Source File: FlickrUploader.java From flickr-uploader with GNU General Public License v2.0 | 4 votes |
private static void initLogs() { Logger logbackLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); LoggerContext lc = logbackLogger.getLoggerContext(); Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.detachAndStopAllAppenders(); TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>(); rollingPolicy.setMaxHistory(3); SizeAndTimeBasedFNATP<ILoggingEvent> sizeAndTimeBasedFNATP = new SizeAndTimeBasedFNATP<ILoggingEvent>(); sizeAndTimeBasedFNATP.setMaxFileSize("2MB"); rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(sizeAndTimeBasedFNATP); rollingPolicy.setFileNamePattern(context.getFilesDir().getPath() + "/logs/old/flickruploader.%d{yyyy-MM-dd}.%i.log"); rollingPolicy.setContext(lc); RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>(); fileAppender.setContext(lc); fileAppender.setFile(getLogFilePath()); fileAppender.setRollingPolicy(rollingPolicy); fileAppender.setTriggeringPolicy(rollingPolicy); rollingPolicy.setParent(fileAppender); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setContext(lc); pl.setCharset(Charset.defaultCharset()); pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %class{0}.%method:%L > %msg%n"); pl.setImmediateFlush(false); pl.start(); fileAppender.setEncoder(pl); fileAppender.setName("file"); rollingPolicy.start(); fileAppender.start(); if (Config.isDebug()) { final PatternLayoutEncoder logcatTagPattern = new PatternLayoutEncoder(); logcatTagPattern.setContext(lc); logcatTagPattern.setPattern("%class{0}"); logcatTagPattern.start(); final PatternLayoutEncoder logcatPattern = new PatternLayoutEncoder(); logcatPattern.setContext(lc); logcatPattern.setPattern("[%thread] %method:%L > %msg%n"); logcatPattern.start(); final LogcatAppender logcatAppender = new LogcatAppender(); logcatAppender.setContext(lc); logcatAppender.setTagEncoder(logcatTagPattern); logcatAppender.setEncoder(logcatPattern); logcatAppender.start(); rootLogger.addAppender(logcatAppender); } rootLogger.addAppender(fileAppender); }