Welcome Guest, Not a member yet? Register   Sign In
Using CI logging from my own library
#1

[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
#2

[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');
#3

[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
#4

[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');
#5

[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

:-)
#6

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




Theme © iAndrew 2016 - Forum software by © MyBB