/** * Convenience of {@link #build()} and {@link Logger#d(String, Object...)}. */ public void d(String format, Object... args) { build().d(format, args); }
/** * Convenience of {@link #build()} and {@link Logger#e(Object[])}. * * @since 1.4.0 */ public void e(Object[] array) { build().e(array); }
/** * Convenience of {@link #build()} and {@link Logger#i(Object)}. * * @since 1.1.0 */ public void i(Object object) { build().i(object); }
/** * Print a log in a new line. * * @param logLevel the log level of the printing log * @param format the format of the printing log, null if just need to concat arguments * @param args the arguments of the printing log */ private void println(int logLevel, String format, Object... args) { if (logLevel < logConfiguration.logLevel) { return; } printlnInternal(logLevel, formatArgs(format, args)); }
/** * Convenience of {@link #build()} and {@link Logger#w(Object)}. * * @since 1.1.0 */ public void w(Object object) { build().w(object); }
/** * Log a message with level {@link LogLevel#VERBOSE}. * * @param format the format of the message to log * @param args the arguments of the message to log */ public static void v(String format, Object... args) { assertInitialization(); sLogger.v(format, args); }
/** * Convenience of {@link #build()} and {@link Logger#log(int, String, Object...)}. * * @since 1.4.0 */ public void log(int logLevel, String format, Object... args) { build().log(logLevel, format, args); }
/** * Log a JSON string, with level {@link LogLevel#DEBUG} by default. * * @param json the JSON string to log */ public static void json(String json) { assertInitialization(); sLogger.json(json); }
/** * Builds configured {@link Logger} object. * * @return the built configured {@link Logger} object */ public Logger build() { return new Logger(this); } }
logger.i(MESSAGE); AssertUtil.assertNoLog(logsContainer); logsContainer.clear(); logger.w(MESSAGE); assertLog(WARN, DEFAULT_TAG, MESSAGE); logsContainer.clear(); logger.e(MESSAGE); assertLog(ERROR, DEFAULT_TAG, MESSAGE); logger.log(-1, MESSAGE); logger.log(0, MESSAGE); logger.log(1, MESSAGE); logger.v(MESSAGE); logger.d(MESSAGE); logger.i(MESSAGE); logger.w(MESSAGE); logger.e(MESSAGE); logger.log(7, MESSAGE); logger.log(8, MESSAGE); logger.log(9, MESSAGE); AssertUtil.assertNoLog(logsContainer); logger.log(-1, MESSAGE); assertLog(-1, DEFAULT_TAG, MESSAGE); logsContainer.clear(); logger.log(0, MESSAGE); assertLog(0, DEFAULT_TAG, MESSAGE); logsContainer.clear(); logger.log(1, MESSAGE);
/** * Convenience of {@link #build()} and {@link Logger#w(String, Throwable)}. */ public void w(String msg, Throwable tr) { build().w(msg, tr); }
/** * Convenience of {@link #build()} and {@link Logger#v(String)}. */ public void v(String msg) { build().v(msg); }
/** * Convenience of {@link #build()} and {@link Logger#log(int, String, Throwable)}. * * @since 1.4.0 */ public void log(int logLevel, String msg, Throwable tr) { build().log(logLevel, msg, tr); }
/** * Convenience of {@link #build()} and {@link Logger#json(String)}. */ public void json(String json) { build().json(json); }
/** * 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); }
/** * Log an object with level {@link LogLevel#WARN}. * * @param object the object to log * @see LogConfiguration.Builder#addObjectFormatter(Class, ObjectFormatter) * @since 1.1.0 */ public static void w(Object object) { assertInitialization(); sLogger.w(object); }
/** * Convenience of {@link #build()} and {@link Logger#v(String, Throwable)}. */ public void v(String msg, Throwable tr) { build().v(msg, tr); }
/** * Convenience of {@link #build()} and {@link Logger#d(String, Throwable)}. */ public void d(String msg, Throwable tr) { build().d(msg, tr); }
/** * Log a message and a throwable with level {@link LogLevel#INFO}. * * @param msg the message to log * @param tr the throwable to be log */ public static void i(String msg, Throwable tr) { assertInitialization(); sLogger.i(msg, tr); }