0

I am trying to log some user activity in a file, like one activity per line

I am using the file helper in order to do so

$this->load->helper('file');
$logline = '[' . date('Y-m-d H:i:s.v') . '] ' . $data['user_id'] . ' | ' . $data['activity'] . '\n';
$logpath = './application/logs/application_activity.log';
return write_file($logpath, $logline, 'a+');

And in my output file, it litterally writes the \n at the end of the line, like this

[2022-03-03 08:49:26.000] Super Administrateur | Validated citizen 1195078 as duplicate\n

How to just make it create a new line at the end of the file?

Side note: if you know where it would be more appropriate to write the logs, please be me guest

prout
  • 317
  • 5
  • 18
  • 1
    You're using single quotes around `'\n'` whereas you intend to use double quotes `"\n"`. See: [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – KIKO Software Mar 03 '22 at 07:11
  • 1
    it was the single quote now I learned something thanks to your link – prout Mar 03 '22 at 07:14

0 Answers0