com.elvishew.xlog.printer.Printer Java Examples

The following examples show how to use com.elvishew.xlog.printer.Printer. 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: XLog.java    From xLog with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize log system, should be called only once.
 *
 * @param logConfiguration the log configuration
 * @param printers         the printers, each log would be printed by all of the printers
 * @since 1.3.0
 */
public static void init(LogConfiguration logConfiguration, Printer... printers) {
  if (sIsInitialized) {
    Platform.get().warn("XLog is already initialized, do not initialize again");
  }
  sIsInitialized = true;

  if (logConfiguration == null) {
    throw new IllegalArgumentException("Please specify a LogConfiguration");
  }
  sLogConfiguration = logConfiguration;

  sPrinter = new PrinterSet(printers);

  sLogger = new Logger(sLogConfiguration, sPrinter);
}
 
Example #3
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 #4
Source File: DefaultsFactory.java    From xLog with Apache License 2.0 4 votes vote down vote up
/**
 * Create the default printer.
 */
public static Printer createPrinter() {
  return Platform.get().defaultPrinter();
}
 
Example #5
Source File: Platform.java    From xLog with Apache License 2.0 4 votes vote down vote up
Printer defaultPrinter() {
  return new ConsolePrinter();
}
 
Example #6
Source File: Platform.java    From xLog with Apache License 2.0 4 votes vote down vote up
@Override
Printer defaultPrinter() {
  return new AndroidPrinter();
}
 
Example #7
Source File: BasicProject.java    From BaseProject with MIT License 2 votes vote down vote up
/**
 * 日志打印参数配置
 *
 * @param printers 打印方式配置
 */
public Builder setLog(@NonNull Printer... printers) {
    mPrinters = printers;
    return this;
}
 
Example #8
Source File: BasicProject.java    From BaseProject with MIT License 2 votes vote down vote up
/**
 * 日志打印参数配置
 *
 * @param logLevel 日志等级
 * @param printers 打印方式配置
 */
public Builder setLog(int logLevel, @NonNull Printer... printers) {
    mLogLevel = logLevel;
    mPrinters = printers;
    return this;
}
 
Example #9
Source File: BasicProject.java    From BaseProject with MIT License 2 votes vote down vote up
/**
 * 日志打印参数配置
 *
 * @param printers 打印方式配置
 */
public Builder setLog(@NonNull Printer... printers) {
    mPrinters = printers;
    return this;
}
 
Example #10
Source File: BasicProject.java    From BaseProject with MIT License 2 votes vote down vote up
/**
 * 日志打印参数配置
 *
 * @param logLevel 日志等级
 * @param printers 打印方式配置
 */
public Builder setLog(int logLevel, @NonNull Printer... printers) {
    mLogLevel = logLevel;
    mPrinters = printers;
    return this;
}
 
Example #11
Source File: Logger.java    From xLog with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a logger.
 *
 * @param logConfiguration the log configuration which you should respect to when logging
 * @param printer          the log printer used to print the log
 */
  /*package*/ Logger(LogConfiguration logConfiguration, Printer printer) {
  this.logConfiguration = logConfiguration;
  this.printer = printer;
}
 
Example #12
Source File: XLog.java    From xLog with Apache License 2.0 2 votes vote down vote up
/**
 * Initialize log system, should be called only once.
 *
 * @param printers the printers, each log would be printed by all of the printers
 * @since 1.3.0
 */
public static void init(Printer... printers) {
  init(new LogConfiguration.Builder().build(), printers);
}
 
Example #13
Source File: XLog.java    From xLog with Apache License 2.0 2 votes vote down vote up
/**
 * Initialize log system, should be called only once.
 *
 * @param logLevel the log level, logs with a lower level than which would not be printed
 * @param printers the printers, each log would be printed by all of the printers
 */
public static void init(int logLevel, Printer... printers) {
  init(new LogConfiguration.Builder().logLevel(logLevel).build(), printers);
}
 
Example #14
Source File: XLog.java    From xLog with Apache License 2.0 2 votes vote down vote up
/**
 * Initialize log system, should be called only once.
 *
 * @param logLevel         the log level, logs with a lower level than which would not be printed
 * @param logConfiguration the log configuration
 * @param printers         the printers, each log would be printed by all of the printers
 * @deprecated the log level is part of log configuration now,
 * use {@link #init(LogConfiguration, Printer...)} instead, since 1.3.0
 */
@Deprecated
public static void init(int logLevel, LogConfiguration logConfiguration, Printer... printers) {
  init(new LogConfiguration.Builder(logConfiguration).logLevel(logLevel).build(), printers);
}