开发中的日志管理类
来源:互联网 发布:从事seo要学些什么 编辑:程序博客网 时间:2024/06/04 19:03
有时候,我们在开发状态下,需要打印一些日志信息,而发布状态下又想去掉这些日志信息(打印出来的信息可能会泄露),如果没有好的日志管理,这时候,你会发现,当初写的日志输出,还有一个一个找出来,然后删掉,所以,一个好的日志管理必不可少。
这是我项目中的一个日志管理类,可自行添加所需的输出方法。
public class MyLog {/** * 是否是开发状态,正式发布要置为false */public static final boolean DEBUG=true;public static void v(Class<?> clzz,String msg){if(DEBUG){Log.v(clzz.getSimpleName(), msg);}}public static void e(Class<?> clzz,String msg){if(DEBUG){Log.e(clzz.getSimpleName(), msg);}}/** * * 2014-8-22 下午3:52:00 * @param msg * @TODO 打印日志输出到文件log.txt */@SuppressLint("SimpleDateFormat")public static void printLog(final String msg){if(!DEBUG) return;new AsyncTask<Void, Void, Void>() {@Overrideprotected Void doInBackground(Void... params) {SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = formatter.format(new Date()); StringBuffer sb = new StringBuffer(); sb.append(time+"\n"); sb.append(msg+"\n"); try { String fileName = "log.txt"; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String path = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator+"cache/"; File dir = new File(path); if (!dir.exists()) { dir.mkdirs(); } File file=new File(path+fileName); if(!file.exists()){ file.createNewFile(); } FileOutputStream fos = new FileOutputStream(path+fileName, true); fos.write(sb.toString().getBytes()); fos.close(); } } catch (Exception e) { } return null;}}.execute();}}
0 0
- 开发中的日志管理类
- android开发中的日志管理类
- 移动开发中的日志管理
- android开发过程中的log日志管理
- mysql中的日志管理
- Android开发--日志管理
- php中的错误日志管理
- Linux系统中的日志管理
- 系统开发中日志管理
- spring aop开发日志管理
- Unity3d游戏开发框架-标志量-数学管理类-时间管理-Log日志管理
- 日志管理类 mfc
- ThinkPHP开发中的日志记录
- spring管理的事务中的日志记录
- 项目日志在项目管理中的应用
- Linux中的日志分析及管理
- Linux中的日志分析及管理
- Linux系统中的系统日志管理
- 使用BusyBox制作linux根文件系统(CramFS+mdev)
- 我们往往对陌生人更加宽容,对最亲的人却更加苛刻
- QML类型说明-Emitter
- 高精度计时器(微秒级)
- js继承
- 开发中的日志管理类
- C 语言用fopen返回值判断某一文件是否存在
- RTMP/RTP/RTSP/RTCP的区别
- ip查询演示代码
- 南京公司注册:工信部:上半年新登记注册企业同比大增近70%
- Linux和windows下socket编程的一点区别
- 高性能图片服务器浅谈
- C++智能指针
- error: C++ preprocessor "/lib/cpp" fails sanity check