Recent

Author Topic: [Solved] Writing to Android logfile.  (Read 455 times)

iru

  • Sr. Member
  • ****
  • Posts: 300
[Solved] Writing to Android logfile.
« on: August 04, 2022, 09:15:21 am »
Environment Win10, Laz 2012, fpc 3.20 Laz4Android2.0.12. All works OK.

Gentlefolk,

How do I write to the Android log file in the JNI application?????
I have a nasty bug/bad-code/? problem addressing a variable length array and writing some log file entries would be a great help.

Ian.
« Last Edit: August 05, 2022, 11:53:46 am by iru »

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1579
Re: Writing to Android logfile.
« Reply #1 on: August 04, 2022, 11:06:54 am »
You might add this into your code.
Code: Pascal  [Select][+][-]
  1. {$ifdef Android}
  2. const
  3.       ANDROID_LOG_UNKNOWN=0;
  4.       ANDROID_LOG_DEFAULT=1;
  5.       ANDROID_LOG_VERBOSE=2;
  6.       ANDROID_LOG_DEBUG=3;
  7.       ANDROID_LOG_INFO=4;
  8.       ANDROID_LOG_WARN=5;
  9.       ANDROID_LOG_ERROR=6;
  10.       ANDROID_LOG_FATAL=7;
  11.       ANDROID_LOG_SILENT=8;
  12.  
  13. function __android_log_write(prio:cint;tag,text:PAnsiChar):cint; cdecl; external 'liblog.so' name '__android_log_write';
  14. {$endif}
In your code, use:
Code: Pascal  [Select][+][-]
  1. procedure ShowLogMessage(value:ansistring);
  2. begin
  3.   {$ifdef Android}
  4.   __android_log_write(ANDROID_LOG_INFO,'my app logger',pansichar(value));
  5.   {$else}
  6.     {$ifndef LCL}
  7.     writeln('my app logger: '+value);
  8.     {$endif}
  9.   {$endif}
  10. end;
  11.  

iru

  • Sr. Member
  • ****
  • Posts: 300
Re: Writing to Android logfile.
« Reply #2 on: August 05, 2022, 08:32:34 am »
Thank you, I will give it a try in the next couple of days. Ian

iru

  • Sr. Member
  • ****
  • Posts: 300
Re: Writing to Android logfile.
« Reply #3 on: August 05, 2022, 11:45:20 am »
Add a 'cTypes' to the 'uses' statement and the program compiles correctly.

Writes to the log file. Now I just have to decipher the results.....

Thank you DonAlfredo you have saved me a lot of time and effort.

Ian

 

TinyPortal © 2005-2018