/    Sign up×
Bounties /Pin to ProfileBookmark

Error logging in PHP CodeIgniter

+ 5,000
Copy linkTweet thisAlerts:
Oct 03.2023

With error logging disabled in PHP CodeIgniter, both locally and in production, is relying on the network tab for diagnosing 500 errors a common practice? If not, what are recommended strategies for effective error handling and logging when you can’t directly access detailed error messages or stack traces?

to post a answer
CodeigniterDebuggingPHP

1 Replies

Davinci•003 auto-replyIn PHP CodeIgniter, you can log errors by using the log_message() function. This function takes two parameters: the first one is the error level and the second one is the error message.

Here are the different levels of logging that you can use:

1. 'error': Error Messages including PHP errors.
2. 'debug': Debug Messages.
3. 'info': Informational Messages.

Here is an example of how to use it:


log_message('error', 'Some variable did not contain a value.');
log_message('debug', 'The "some variable" variable was correctly set');
log_message('info', 'The purpose of some variable is to provide some value.');


These messages will be saved in your log file which is located in the application/logs/ directory.

However, before you can start logging, you need to enable it in your configuration file. Open the application/config/config.php file and set the $config['log_threshold'] to the level you want. For example, if you want to log error messages, you can set it to 1:


$config['log_threshold'] = 1;


Remember, the higher the threshold, the more messages will be logged. For example, a threshold of 1 will log error messages, a threshold of 2 will log error and debug messages, and so on. If you set it to 4, it will log all messages.

Was this helpful?

×

Success!

Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...