CodeIgniter Forums
Using CI logging from my own library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Using CI logging from my own library (/thread-34761.html)



Using CI logging from my own library - El Forum - 10-08-2010

[eluser]matthew1471[/eluser]
Hi,

I've created my own library, but when I try to use the CI logging library in it, nothing gets logged.

I know the logging is set up correctly, as it works in other sections of my code.

Any ideas?

Cheers,
Matt


Using CI logging from my own library - El Forum - 10-08-2010

[eluser]bretticus[/eluser]
Hi Matt,

When you say "CI logging library," do you mean you're calling the CI function:

Code:
log_message('level', 'message');

If so, check your settings in your application/config/config.php file to see what level is set to.

FYI, in case you didn't know, when using your own libraries, you have to grab an instance of CodeIgniter to use actual Ci libraries:

Code:
$CI =& get_instance();
$some_item = $CI->config->item('some_item');



Using CI logging from my own library - El Forum - 10-08-2010

[eluser]matthew1471[/eluser]
Hi bretticus,

Yep, I'm using

Code:
$this->log_message('info', 'log message');

to log the message.

The logging level is set correctly in the config, as I'm using the same 'info' level in other parts of my code, and items are being logged OK.

I'm also using

Code:
$ci =& get_instance();

to pull in the rest of the CI libraries.

Weird... I'll keep on looking!

Cheers,
Matt


Using CI logging from my own library - El Forum - 10-08-2010

[eluser]bretticus[/eluser]
log_message() is a function in scope for the entire framework. It is not a method of the current object (your library class.) The reason you can call CI objects via $this under your Controller (can you really call $this->log_message() in your Controller?) is because your controller extends the Controller class. Your library most likely extends nothing (at least nothing with a log_message() method.)

Try changing:

Code:
$this->log_message('info', 'log message');

to just:

Code:
log_message('info', 'log message');



Using CI logging from my own library - El Forum - 10-09-2010

[eluser]matthew1471[/eluser]
ha ha ha. What a doughnut.

I've spent the best part of a day trying to figure out why it wouldn't log from my own library.

Result: I was putting the log call in the WRONG library.

:-S

Time to take a break. Thanks for your advice bretticus

:-)


Using CI logging from my own library - El Forum - 10-09-2010

[eluser]bretticus[/eluser]
Believe me, I've had my share of wall-head-banging days too! Smile