Stream android logcat output to an sd card

后端 未结 4 707
孤街浪徒
孤街浪徒 2020-12-18 04:16

I want to achieve the following but so far, no luck

  • Open a file in the SD Card when the android application first started.
  • Stream the logcat output to
4条回答
  •  星月不相逢
    2020-12-18 04:43

    I know this is a late answer to the question but I would highly recommend using Logback to write messages to a log file as well as the logcat.

    1. Copy logback-android-1.0.10-2.jar and slf4j-api-1.7.5.jar to your libs folder.
    2. Right-Click on both libs and from the menu select Build Path -> Add to Build Path.
    3. Create a logback.xml file in your assets folder and enter the following:
    
    
      
    
      
      
        
          %msg
        
      
    
      
      
        
          WARN
        
    
        ${LOG_DIR}/log.txt
    
        
          %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
          
      
    
      
      
        
        
      
    
    1. To write a log:

      public class MyActivity extends Activity { public static final Logger logger = LoggerFactory.getLogger(MyActivity.class);

      protected void onCreate(Bundle b)
      {
          super(b);
          try{
              throw new Exception("Test");
          }catch(Exception e){
              logger.error("Something bad happened",e);
          }
      }
      

      }

提交回复
热议问题