0

I'm attempting to add logging into my CI project. I have added the Error Logging Threshold in config as $config['log_threshold'] = 2; and kept the log path empty $config['log_path'] = ''; I'm writing the logging in my controller as

    $product = $this->Pizza_Model->find_pizza($id);
        if ($product == '')
    {
        log_message('error', 'Pizza is not fetched from database');
    }
    else
    {
        log_message('debug', 'Pizza was fetched'.print_r($product,TRUE));
    }

When i run my application nothing is written on the logs folder. Do i have to specifically give the log path in the config file for logs to be written? if so how can i give the log path in the config file?

CodeGirl
  • 49
  • 8
  • since your `$config['log_path']` is empty, you shoud look in `appplication/logs/` ... depending on your server configuration, even if the permissions are OK, check that the logs directory is owned by the same process that runs Apache or Nginx depending on what you use... otherwise, that could be a reason for the logs not to be written – Javier Larroulet Nov 10 '20 at 18:56

1 Answers1

1

$config['log_path'] is supposed to be a path to a directory, not a file. Try a path to a directory, and make sure to include a trailing slash.

Also try 755 (or 777 be careful) permissions on directory if it still doesn't work.

EX. $config['log_path'] = '/var/log/ci_logs/';

  • `/Users/***/.bitnami/stackman/machines/xampp/volumes/root/htdocs/2017413/PizzaNow2/application/logs/` should i provide the full file path like this? – CodeGirl Nov 10 '20 at 16:34
  • 1
    are you using docker? you may provide full path. dont forget to run `sudo chmod -R 777 /Users/***/.bitnami/stackman/machines/xampp/volumes/root/htdocs/2017413/PizzaNow2/application/logs/` if it still doesn't work. – Mohit Deshwal Nov 10 '20 at 16:38
  • Thank you. It works after giving 777 permissions to the directory – CodeGirl Nov 10 '20 at 16:44
  • Not a good idea to assign 777 permissions. Not ever. This opens the gate for external users reading your logs and eventually getting information that can be used for other purposes. – Javier Larroulet Nov 11 '20 at 12:28
  • please refer to https://stackoverflow.com/questions/13729828/codeigniter-not-logging ,read comments. Some users having issues with only valid option i.e 755 – Mohit Deshwal Nov 11 '20 at 12:29
  • The fact that CI doesn't write logs unless you use an insecure set of permissions doesn't mean that the correct way to address the problem is that. It usually is a problem regarding directory OWNERSHIP not permissions – Javier Larroulet Nov 11 '20 at 14:34
  • Correct @JavierLarroulet, I don't know how to communicate that in concise answer. You may edit my answer. :) – Mohit Deshwal Nov 11 '20 at 14:39