2014-02-26 1 views
0

내 OS는 JellyBean입니다. Logcat 로그를 수집하고 5 분마다 txt 파일로 저장하는 안드로이드 서비스가 있습니다. 그러나 문제가 있습니다. 내가 그안드로이드 쓰레드가 Logcat 로그를 읽지 못합니다

@Override 
public void onCreate() 
{ 
     // TODO Auto-generated method stub 
    Toast.makeText(getApplicationContext(), "Service Üretildi", 1).show(); 
    super.onCreate(); 
    process = Runtime.getRuntime() 
        .exec("logcat -d -b main -v time"); 
. 
. 
. 
} 

threads.like 어떤없이 코딩 된 첫 번째 경우가 더 problem.Application 시스템 로그를 수집하지 않습니다이었다 properly.But 내가 TimerTask를 그것은 내가해야 할 유일한 TestService의 디버그 logs.What를 기록 할 수의 스레드를 사용하는 경우 ?

public class TestService extends Service 
{ 

    @Override 
    public void onCreate() 
    { 
     // TODO Auto-generated method stub 
     Toast.makeText(getApplicationContext(), "Service Üretildi", 1).show(); 
     super.onCreate(); 
     runService(); 

    } 

    private void runService() 
    { 
     timer.scheduleAtFixedRate(new runningTask(), 0, 300 * 1000); 
    } 

    private class runningTask extends TimerTask 
    { 

     @Override 
     public void run() 
     { 
      Log.i("LOGTEST", "LOGTEST"); 

      try 
      { 
       process = Runtime.getRuntime() 
         .exec("logcat -d -b main -v time"); 
      } 
      catch (IOException e) 
      { 
       Log.e("LOGTEST", e.getMessage()); 
      } 

      Log.i("LOGTEST", "COLLECTED"); 
      bufferedReader = new BufferedReader(new InputStreamReader(
        process.getInputStream())); 

      StringBuilder log = new StringBuilder(); 
      String line; 
      try 
      { 
       while ((line = bufferedReader.readLine()) != null) 
       { 
        log.append(line); 
        log.append("\n"); 
       } 
       // log = stabilizing(log); 
       bufferedReader.close(); 
      } 
      catch (IOException e) 
      { 
       Log.e("LOGTEST", e.getMessage()); 
      } 

      String logFilePath = Environment.getExternalStorageDirectory() 
        + File.separator + "AAAA" + i + ".txt"; 
      i++; 
      File logFile = new File(logFilePath); 
      if (!logFile.exists()) 
       try 
       { 
        logFile.createNewFile(); 
        FileOutputStream outStream = new FileOutputStream(logFile, 
          true); 
        byte[] buffer = log.toString().getBytes(); 

        outStream.write(buffer); 
        outStream.close(); 
       } 
       catch (IOException e) 
       { 
        Log.e("LOGTEST", e.getMessage()); 
       } 

       // Runtime.getRuntime().exec("logcat -c"); 
       finally 
       { 
        process.destroy();; 
       } 

     } 

    } 



} 

답변

0

제 생각에는 JellyBean 릴리스 (4.2) 이후 뿌리가없는 장치에서는이 작업을 수행 할 수 없었습니다. 장치를 루트로 설정하면 시스템 로그에 액세스 할 수 있어야합니다. 장치를 루트하지 않으면 응용 프로그램 내부에서 생성 된 로그에만 액세스 할 수 있다고 생각합니다.

+0

내 로그에 액세스하지만 5 분마다 logcat 로그를 txt로 읽고 쓰고 싶습니다. – yfpayalan

관련 문제