0

I'm using log4php and I have basically wrapped it so when any of my classes call Logger they also initalise it with getLogger and name the logger based on the namespace of the calling class

e.g.

namespace my\class\space

Logger::GetInstance(NAME_SPACE)

will create a logger with the name my\class\space (it actually gets prefixed as well inside my wrapper to something like instance\my\class\space).

How do I write a log4php config to dump all log files to the default (root) logger but then specify other loggers based on the certain namespaces I'm interested in.

e.g. I would like to do something like

<logger name="instance\my\class\space">

and that logs those class and sub class messages to a different file to everything else.

Any ideas?

Thanks

UPDATE

<logger name="instance\my\class\space" additivity="false">

will log my instance\my\class\space to a different file, but it is not including sub packages e.g.

instance\my\class\space\sub is still being logged in root. I thought log4j automatically handled sub packages, does log4php not support this?

TheStoneFox
  • 3,007
  • 3
  • 31
  • 47

1 Answers1

0

Ok. so it looks as if log4php does support sub classes but you use the log4j dot package separator notation and not the php namespace separator notation.

i.e.

instance\my\class\space is the php namespace

but log4php seems to need that converting into a java package namespace of

instance.my.class.space

then log4php will automatically read sub classes of any sub named loggers such as

instance.my.class.space.sub

without adding any more lines to the config file

TheStoneFox
  • 3,007
  • 3
  • 31
  • 47
  • lol yeah I know, I saw in the end. It was because I had my loggers being named exactly as the php namespaced classes. Why doesn't log4php support php namespaces?! It's hardly 4php :p – TheStoneFox Apr 05 '13 at 14:22
  • Log4PHP does not impose any logger name convention, you are free to use it the way it fits your needs. Converting a classname into a logger name is a good idea, but even with pre-5.3 classnames you had to transform underscores into dots. Now the same with backslashes, and stripping the one in front. – Sven Apr 05 '13 at 18:34