logging to two different files with log4php

Is there a way to make log4php write to two different files, and keep those separate from each other, based on the log level?

I managed to write INFO data to a file, and ERROR data to another using the property file below. But the problem is
that when I ask log4php to write to the ERROR log, it also prints it in the INFO one. Please take a look and let me know if
there is a way not to write to INFO appender when I specify ERROR:


Configuration file:

# Setup for the summary log file:
log4php.appender.A1=LoggerAppenderDailyFile
log4php.appender.A1.MaxFileSize=1MB
log4php.appender.A1.MaxBackupIndex=1
log4php.appender.A1.layout=LoggerLayoutTTCC
log4php.appender.A1.layout.ContextPrinting="true"
log4php.appender.A1.layout.DateFormat="%c"
log4php.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4php.appender.A1.File=logs/log_summary_%s.log
log4php.appender.A1.Threshold=INFO
# NOTE: The commented out lines didn't do the trick, I was just copying from the java implementation...
#log4php.appender.A1.varia.LevelRangeFilter.LevelMin=INFO
#log4php.appender.A1.varia.LevelRangeFilter.LevelMax=INFO

# Setup for the errors log file:
log4php.appender.A2=LoggerAppenderDailyFile
log4php.appender.A2.MaxFileSize=1MB
log4php.appender.A2.MaxBackupIndex=1
log4php.appender.A2.layout=LoggerLayoutTTCC
log4php.appender.A2.layout.ContextPrinting="true"
log4php.appender.A2.layout.DateFormat="%c"
log4php.appender.A2.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4php.appender.A2.File=logs/log_errors_%s.log
log4php.appender.A2.Threshold=ERROR
# NOTE: The commented out lines didn't do the trick, I was just copying from the java implementation...
#log4php.appender.A2.varia.LevelRangeFilter.LevelMin=ERROR
#log4php.appender.A2.varia.LevelRangeFilter.LevelMax=ERROR


log4php.rootLogger=debug, A1, A2


And the way I am calling log4php:


// Summary logging (works, doesn't write to error log, only to summary log as expected):
$logger = LoggerManager::getLogger('myFunctionHere');
$logger->info($data_to_log_here);

// Error logging (works, but writes to both summary and error logs, I only want this to go to the error file):
$logger = LoggerManager::getLogger('myFunctionHere');
$logger->error($data_to_log_here);
cabrera48Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Matthew KellyCommented:
I think it probably has something to do with the appender additivity flag defaulting to true. Try splitting the two appenders into different categories, or setting additivity to false.

http://logging.apache.org/log4j/1.2/manual.html

Appender Additivity
The output of a log statement of logger C will go to all the appenders in C and its ancestors. This is the meaning of the term "appender additivity".

However, if an ancestor of logger C, say P, has the additivity flag set to false, then C's output will be directed to all the appenders in C and it's ancestors upto and including P but not the appenders in any of the ancestors of P.

Loggers have their additivity flag set to true by default
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cabrera48Author Commented:
That was it, thanks matthewstevenkelly,
The coded solution below just in case anybody else needs it later:

# Setup for the summary log file:

log4php.appender.A1=LoggerAppenderDailyFile
log4php.appender.A1.MaxFileSize=1MB
log4php.appender.A1.MaxBackupIndex=10
log4php.appender.A1.layout=LoggerLayoutTTCC
log4php.appender.A1.layout.DateFormat="%c"
log4php.appender.A1.File=logs/summary/log_summary_%s.log
log4php.appender.A1.Threshold=INFO

log4php.rootLogger=DEBUG, A1
log4php.additivity.rootLogger="false"

# Setup for the errors log file:
log4php.logger.errorLogger = ERROR, A2
log4php.additivity.errorLogger="false"

log4php.appender.A2=LoggerAppenderDailyFile
log4php.appender.A2.MaxFileSize=1MB
log4php.appender.A2.MaxBackupIndex=1
log4php.appender.A2.layout=LoggerLayoutTTCC
log4php.appender.A2.layout.DateFormat="%c"
log4php.appender.A2.File=logs/errors/log_errors_%s.log
log4php.appender.A2.Threshold=ERROR
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.