com.elvishew.xlog.LogLevel Java Examples

The following examples show how to use com.elvishew.xlog.LogLevel. 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: LogUtils.java    From MiPushFramework with GNU General Public License v3.0 6 votes vote down vote up
public static void init (@NonNull Context context) {

        int logLevel = LogLevel.INFO;
        if (BuildConfig.DEBUG) {
            logLevel = LogLevel.ALL;
        }
        LogConfiguration configuration = new LogConfiguration.Builder()
                .tag("Xmsf")
                .logLevel(logLevel)
                .jsonFormatter(new DefaultJsonFormatter())
                .xmlFormatter(new DefaultXmlFormatter())
                .stackTraceFormatter(new DefaultStackTraceFormatter())
                .build();
        Printer androidPrinter = new AndroidPrinter();
        Printer filePrinter = new FilePrinter.Builder(LogUtils.getLogFolder(context))
                .fileNameGenerator(new DateFileNameGenerator())
                .cleanStrategy(new FileLastModifiedCleanStrategy(7 * 24 * 60 * 60 * 1000 /* 7 days */))
                .build();
        XLog.init(configuration, androidPrinter, filePrinter);
    }
 
Example #2
Source File: RecyclerViewPrinter.java    From xLog with Apache License 2.0 6 votes vote down vote up
/**
 * Get the highlight color for specific log level.
 *
 * @param logLevel the specific log level
 * @return the highlight color
 */
private int getHighlightColor(int logLevel) {
  int hightlightColor;
  switch (logLevel) {
    case LogLevel.VERBOSE:
      hightlightColor = 0xffbbbbbb;
      break;
    case LogLevel.DEBUG:
      hightlightColor = 0xffffffff;
      break;
    case LogLevel.INFO:
      hightlightColor = 0xff6a8759;
      break;
    case LogLevel.WARN:
      hightlightColor = 0xffbbb529;
      break;
    case LogLevel.ERROR:
      hightlightColor = 0xffff6b68;
      break;
    default:
      hightlightColor = 0xffffff00;
      break;
  }
  return hightlightColor;
}
 
Example #3
Source File: BaseApp.java    From PhotoOut with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    PhotoUtil.init(getApplicationContext(),new FrescoIniter());
    //Logger.initialize(new Settings());
    XLog.init(LogLevel.ALL);
}
 
Example #4
Source File: ClassicApplication.java    From BaseProject with MIT License 5 votes vote down vote up
@Override public void onCreate() {
    super.onCreate();

    final BasicProject.Builder builder = new BasicProject.Builder()
            .setDebug(BuildConfig.DEBUG)
            .setRootDirectoryName(getPackageName())
            //自定义异常信息处理,实现ICrashProcess
            //.setExceptionHandler(new CustomCrashProcessImpl())
            .setLog(BuildConfig.DEBUG ? LogLevel.ALL : LogLevel.NONE);

    BasicProject.config(builder);
    Adapter.config(new Adapter.Builder().setImageLoad(new GlideImageLoad()));
}
 
Example #5
Source File: PatternFlattener.java    From xLog with Apache License 2.0 5 votes vote down vote up
@Override
protected String fill(String pattern, long timeMillis, int logLevel, String tag, String message) {
  if (useLongName) {
    return pattern.replace(wrappedParameter, LogLevel.getLevelName(logLevel));
  } else {
    return pattern.replace(wrappedParameter, LogLevel.getShortLevelName(logLevel));
  }
}
 
Example #6
Source File: DefaultFlattener.java    From xLog with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence flatten(long timeMillis, int logLevel, String tag, String message) {
  return Long.toString(timeMillis)
      + '|' + LogLevel.getShortLevelName(logLevel)
      + '|' + tag
      + '|' + message;
}
 
Example #7
Source File: AndroidPrinterTest.java    From xLog with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  XLogUtil.beforeTest();
  XLog.init(LogLevel.ALL, new AndroidPrinter() {
    @Override
    void printChunk(int logLevel, String tag, String msg) {
      logContainer.add(new LogItem(logLevel, tag, msg));
    }
  });
}
 
Example #8
Source File: MainActivity.java    From xLog with Apache License 2.0 4 votes vote down vote up
/**
 * Print the configured log.
 */
private void printLog() {
  Logger.Builder builder = new Logger.Builder();

  String tag = tagView.getText().toString();
  if (!TextUtils.isEmpty(tag)) {
    builder.tag(tag);
  }

  if (threadInfo.isChecked()) {
    builder.t();
  } else {
    builder.nt();
  }

  if (stackTraceInfo.isChecked()) {
    builder.st(STACK_TRACE_DEPTHS[stackTraceDepth.getSelectedItemPosition()]);
  } else {
    builder.nst();
  }

  if (border.isChecked()) {
    builder.b();
  } else {
    builder.nb();
  }

  // Print the log to view, logcat and file.
  if (hasPermission) {
    builder.printers(
        viewPrinter,
        new AndroidPrinter(),
        XLogSampleApplication.globalFilePrinter);
  } else {
    builder.printers(
        viewPrinter,
        new AndroidPrinter());
  }

  Logger logger = builder.build();

  int levelPosition = levelView.getSelectedItemPosition();
  int level = LEVELS[levelPosition];
  switch (level) {
    case LogLevel.VERBOSE:
      logger.v(MESSAGE);
      break;
    case LogLevel.DEBUG:
      logger.d(MESSAGE);
      break;
    case LogLevel.INFO:
      logger.i(MESSAGE);
      break;
    case LogLevel.WARN:
      logger.w(MESSAGE);
      break;
    case LogLevel.ERROR:
      logger.e(MESSAGE);
      break;
  }
}
 
Example #9
Source File: XLogSampleApplication.java    From xLog with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize XLog.
 */
private void initXlog() {
  LogConfiguration config = new LogConfiguration.Builder()
      .logLevel(BuildConfig.DEBUG ? LogLevel.ALL             // Specify log level, logs below this level won't be printed, default: LogLevel.ALL
          : LogLevel.NONE)
      .tag(getString(R.string.global_tag))                   // Specify TAG, default: "X-LOG"
      // .t()                                                // Enable thread info, disabled by default
      // .st(2)                                              // Enable stack trace info with depth 2, disabled by default
      // .b()                                                // Enable border, disabled by default
      // .jsonFormatter(new MyJsonFormatter())               // Default: DefaultJsonFormatter
      // .xmlFormatter(new MyXmlFormatter())                 // Default: DefaultXmlFormatter
      // .throwableFormatter(new MyThrowableFormatter())     // Default: DefaultThrowableFormatter
      // .threadFormatter(new MyThreadFormatter())           // Default: DefaultThreadFormatter
      // .stackTraceFormatter(new MyStackTraceFormatter())   // Default: DefaultStackTraceFormatter
      // .borderFormatter(new MyBoardFormatter())            // Default: DefaultBorderFormatter
      // .addObjectFormatter(AnyClass.class,                 // Add formatter for specific class of object
      //     new AnyClassObjectFormatter())                  // Use Object.toString() by default
      .addInterceptor(new BlacklistTagsFilterInterceptor(    // Add blacklist tags filter
          "blacklist1", "blacklist2", "blacklist3"))
      // .addInterceptor(new WhitelistTagsFilterInterceptor( // Add whitelist tags filter
      //     "whitelist1", "whitelist2", "whitelist3"))
      // .addInterceptor(new MyInterceptor())                // Add a log interceptor
      .build();

  Printer androidPrinter = new AndroidPrinter();             // Printer that print the log using android.util.Log
  Printer filePrinter = new FilePrinter                      // Printer that print the log to the file system
      .Builder(new File(Environment.getExternalStorageDirectory(), "xlogsample").getPath())       // Specify the path to save log file
      .fileNameGenerator(new DateFileNameGenerator())        // Default: ChangelessFileNameGenerator("log")
      // .backupStrategy(new MyBackupStrategy())             // Default: FileSizeBackupStrategy(1024 * 1024)
      // .cleanStrategy(new FileLastModifiedCleanStrategy(MAX_TIME))     // Default: NeverCleanStrategy()
      .flattener(new ClassicFlattener())                     // Default: DefaultFlattener
      .build();

  XLog.init(                                                 // Initialize XLog
      config,                                                // Specify the log configuration, if not specified, will use new LogConfiguration.Builder().build()
      androidPrinter,                                        // Specify printers, if no printer is specified, AndroidPrinter(for Android)/ConsolePrinter(for java) will be used.
      filePrinter);

  // For future usage: partial usage in MainActivity.
  globalFilePrinter = filePrinter;
}
 
Example #10
Source File: LevelFileNameGenerator.java    From xLog with Apache License 2.0 4 votes vote down vote up
/**
 * Generate a file name which represent a specific log level.
 */
@Override
public String generateFileName(int logLevel, long timestamp) {
  return LogLevel.getLevelName(logLevel);
}
 
Example #11
Source File: WhitelistTagsFilterInterceptorTest.java    From xLog with Apache License 2.0 4 votes vote down vote up
private void assertTagAccepted(String tag) {
  LogItem log = new LogItem(LogLevel.DEBUG, tag, "Message");
  assertNotNull("Tag " + log.tag + " should be accepted", interceptor.intercept(log));
}
 
Example #12
Source File: WhitelistTagsFilterInterceptorTest.java    From xLog with Apache License 2.0 4 votes vote down vote up
private void assertTagRejected(String tag) {
  LogItem log = new LogItem(LogLevel.DEBUG, tag, "Message");
  assertNull("Tag " + log.tag + " should be rejected", interceptor.intercept(log));
}
 
Example #13
Source File: BlacklistTagsFilterInterceptorTest.java    From xLog with Apache License 2.0 4 votes vote down vote up
private void assertTagAccepted(String tag) {
  LogItem log = new LogItem(LogLevel.DEBUG, tag, "Message");
  assertNotNull("Tag " + log.tag + " should be accepted", interceptor.intercept(log));
}
 
Example #14
Source File: BlacklistTagsFilterInterceptorTest.java    From xLog with Apache License 2.0 4 votes vote down vote up
private void assertTagRejected(String tag) {
  LogItem log = new LogItem(LogLevel.DEBUG, tag, "Message");
  assertNull("Tag " + log.tag + " should be rejected", interceptor.intercept(log));
}