com.elvishew.xlog.XLog Java Examples
The following examples show how to use
com.elvishew.xlog.XLog.
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 |
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: BasicProject.java From BaseProject with MIT License | 6 votes |
private void setConfig() { if (null != mExceptionHandler) { CrashHandler.getInstance(mExceptionHandler); } if (null != mPrinters && null != mLogConfiguration) { XLog.init(mLogConfiguration, mPrinters); } else if (null != mLogLevel && null != mPrinters) { XLog.init(mLogLevel, mPrinters); } else if (null != mPrinters) { XLog.init(mPrinters); } else if (null != mLogConfiguration) { XLog.init(mLogConfiguration); } else if (null != mLogLevel) { XLog.init(mLogLevel); } else { XLog.init(); } }
Example #3
Source File: BasicProject.java From BaseProject with MIT License | 6 votes |
private void setConfig() { if (!TextUtils.isEmpty(mRootDirectoryName)) { SDCardUtil.setRootDirName(mRootDirectoryName); } SDCardUtil.initDir(); if (null != mExceptionHandler) { CrashHandler.getInstance(mExceptionHandler); } if (null != mPrinters && null != mLogConfiguration) { XLog.init(mLogConfiguration, mPrinters); } else if (null != mLogLevel && null != mPrinters) { XLog.init(mLogLevel, mPrinters); } else if (null != mPrinters) { XLog.init(mPrinters); } else if (null != mLogConfiguration) { XLog.init(mLogConfiguration); } else if (null != mLogLevel) { XLog.init(mLogLevel); } else { XLog.init(); } }
Example #4
Source File: AndroidPrinterTest.java From xLog with Apache License 2.0 | 6 votes |
@Test public void testPrintLongMessage() throws Exception { int messageChunkLength = AndroidPrinter.DEFAULT_MAX_CHUNK_SIZE; int length = (int) (3.6 * messageChunkLength); StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { sb.append(RandomUtil.randomAsciiChar()); } String msg = sb.toString(); XLog.d(msg); assertEquals(4, logContainer.size()); int start = 0; int end = 0; for (int i = 0; end < length; i++) { end = AndroidPrinter.adjustEnd(msg, start, Math.min(start + messageChunkLength, length)); String chunk = msg.substring(start, end); AssertUtil.assertHasLog(logContainer, i, chunk); start = end; } }
Example #5
Source File: ProxyTools.java From PhotoOut with Apache License 2.0 | 5 votes |
public static <T> T getShowMethodInfoProxy(final T realObj){ return (T) Proxy.newProxyInstance(ProxyTools.class.getClassLoader(), realObj.getClass().getInterfaces(), new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { XLog.e("method name:"+ method.getName() + "--args:"+ Arrays.toString(args)); Object o = method.invoke(realObj,args); return o; } }); }
Example #6
Source File: BaseApp.java From PhotoOut with Apache License 2.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); PhotoUtil.init(getApplicationContext(),new FrescoIniter()); //Logger.initialize(new Settings()); XLog.init(LogLevel.ALL); }
Example #7
Source File: MainActivity.java From xLog with Apache License 2.0 | 5 votes |
@Override protected void onResume() { super.onResume(); String message; hasPermission = hasPermission(); if (hasPermission) { message = "Permission granted.\nLog to file."; } else { message = "Permission not granted.\nCan not log to file."; } XLog.printers(viewPrinter).i(message); }
Example #8
Source File: AndroidPrinterTest.java From xLog with Apache License 2.0 | 5 votes |
@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 #9
Source File: AndroidPrinterTest.java From xLog with Apache License 2.0 | 5 votes |
@Test public void testPrintShortMessage() throws Exception { String msg = "This is a short message"; XLog.d(msg); assertEquals(1, logContainer.size()); AssertUtil.assertHasLog(logContainer, msg); }
Example #10
Source File: AndroidPrinterTest.java From xLog with Apache License 2.0 | 5 votes |
@Test public void testPrint4kMessage() throws Exception { int length = AndroidPrinter.DEFAULT_MAX_CHUNK_SIZE; StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { sb.append(RandomUtil.randomAsciiChar()); } String msg = sb.toString(); XLog.d(msg); assertEquals(1, logContainer.size()); AssertUtil.assertHasLog(logContainer, msg); }
Example #11
Source File: XMOutbound.java From MiPushFramework with GNU General Public License v3.0 | 4 votes |
private XMOutbound (Context context, String tag) { this.context = context; this.logger = XLog.tag(tag).build(); }
Example #12
Source File: HttpObserver.java From BaseProject with MIT License | 4 votes |
/** * 接口调用之前会检测网络,如果无网络执行此回调方法 */ public void onNetworkNotConnected() { if (isDebug) { XLog.tag(TAG).e(mAppContext.getResources().getString(R.string.network_error_hint)); } }
Example #13
Source File: HttpObserver.java From BaseProject with MIT License | 4 votes |
/** 网络连接超时回调 */ public void onSocketTimeout() { if (isDebug) { XLog.tag(TAG).e(mAppContext.getResources().getString(R.string.network_timeout_hint)); } }
Example #14
Source File: HttpObserver.java From BaseProject with MIT License | 4 votes |
/** * 请求失败回调 * * @param e 异常信息 */ public void onFailure(Throwable e) { if (isDebug && null != e && !TextUtils.isEmpty(e.getMessage())) { XLog.tag(TAG).e(e.getMessage()); } }
Example #15
Source File: MainActivity.java From BaseProject with MIT License | 4 votes |
@Override public void onFirst() { super.onFirst(); XLog.d("onFirst只有第一次才会执行"); //这里可以做一些界面功能引导 }
Example #16
Source File: XLogSampleApplication.java From xLog with Apache License 2.0 | 4 votes |
/** * 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; }