Discussion:
[log4perl-devel] Error when re-initializing log4perl
Marc Zampetti
2013-03-15 20:54:21 UTC
Permalink
I have a program that configures a basic Log4perl config so that I have
some sane logging until I'm able to read in the config file with the
final configuration. I'm getting an error when calling
Log::Log4perl->init() the second time that I cannot seem to track down.
Lee
2013-03-16 08:08:56 UTC
Permalink
I don't know the L4p source, but I vaguely recall that someone, years
ago, possibly in the Log4perl docs, said that the init method was only
intended to implement initialisation, not re-initialisation.

I may be wrong — I can't imagine ever calling init() twice, though I did
occasionally do it when I first started using the system, there was some
now-forgotten issue that stopped the practice.

Why are you calling init twice?

If it is just in case the config has chanced, there is an init-and-watch
method.

If it is to combine configurations, the Hash::Merge module can help, and
there is a working example somewhere in the archives of this group.

HTH
Post by Marc Zampetti
I have a program that configures a basic Log4perl config so that I have
some sane logging until I'm able to read in the config file with the
final configuration. I'm getting an error when calling
Log::Log4perl->init() the second time that I cannot seem to track down.
Marc Zampetti
2013-03-16 18:19:22 UTC
Permalink
The use case is the situation where I don't know what the config file with
the logging configuration is yet. So basically, the program does the
following:

1. Initializes the logging system as soon as it starts, before anything
else, with a basic config that will log to stdout.
2. Process the command line parameters, does some other configuration work,
which includes figuring out where the correct logging configuration file
is. I need a valid logging system because there may be cases in this phase
that log messages get generated, say for missing information or a
filesystem permission issue, etc.
3. Calls init() with the new config file, to setup the real logging that
should be done for the rest of the application.

I cannot use the init_and_watch() method, because I don't have a config
file to use yet. Not to mention, the init_and_watch has some performance
issues.

So basically the question I have is that I need to reset and re-configure
the logging system at some point after the initial logging setup. The docs
for the init() and init_once() methods suggest that calling init() a second
time will "reset" and "overwrite" the current configuration, which in this
case I want.

I hope that helps.
I don't know the L4p source, but I vaguely recall that someone, years ago,
possibly in the Log4perl docs, said that the init method was only intended
to implement initialisation, not re-initialisation.
I may be wrong — I can't imagine ever calling init() twice, though I did
occasionally do it when I first started using the system, there was some
now-forgotten issue that stopped the practice.
Why are you calling init twice?
If it is just in case the config has chanced, there is an init-and-watch
method.
If it is to combine configurations, the Hash::Merge module can help, and
there is a working example somewhere in the archives of this group.
HTH
Post by Marc Zampetti
I have a program that configures a basic Log4perl config so that I have
some sane logging until I'm able to read in the config file with the
final configuration. I'm getting an error when calling
Log::Log4perl->init() the second time that I cannot seem to track down.
Mike Schilli
2013-03-18 00:32:37 UTC
Permalink
Post by Marc Zampetti
So basically the question I have is that I need to reset and
re-configure the logging system at some point after the initial
logging setup. The docs for the init() and init_once() methods suggest
that calling init() a second time will "reset" and "overwrite" the
current configuration, which in this case I want.
Can you try if calling

Log::Log4perl->reset()

before calling init() the second time fixes the problem?

-- -- Mike

Mike Schilli
Post by Marc Zampetti
In the test suite,
I hope that helps.
I don't know the L4p source, but I vaguely recall that
someone, years ago, possibly in the Log4perl docs, said that
the init method was only intended to implement
initialisation, not re-initialisation.
I may be wrong — I can't imagine ever calling init() twice,
though I did occasionally do it when I first started using
the system, there was some now-forgotten issue that stopped
the practice.
Why are you calling init twice?
If it is just in case the config has chanced, there is an
init-and-watch method.
If it is to combine configurations, the Hash::Merge module
can help, and there is a working example somewhere in the
archives of this group.
HTH
I have a program that configures a basic Log4perl
config so that I have
some sane logging until I'm able to read in the config
file with the
final configuration. I'm getting an error when calling
Log::Log4perl->init() the second time that I cannot
seem to track down.
Mike Schilli
2013-03-19 00:02:01 UTC
Permalink
No, adding Log::Log4perl->reset()
before the second call to Log::log4perl->init() doesn't fix anything. So
far, the only solution is to remove one of the calls to
Log::Log4perl->init().
Do you have some code that reproduces the problem so I can take a look?
--
-- Mike

Mike Schilli
Marc
So basically the question I have is that I need to
reset and
re-configure the logging system at some point after the initial
logging setup. The docs for the init() and
init_once() methods suggest
that calling init() a second time will "reset" and
"overwrite" the
current configuration, which in this case I want.
Can you try if calling
    Log::Log4perl->reset()
before calling init() the second time fixes the problem?
-- -- Mike
Mike Schilli
In the test suite,
I hope that helps.
      I don't know the L4p source, but I vaguely recall
that
      someone, years ago, possibly in the Log4perl docs,
said that
      the init method was only intended to implement
      initialisation, not re-initialisation.
      I may be wrong — I can't imagine ever calling init()
twice,
      though I did occasionally do it when I first started
using
      the system, there was some now-forgotten issue that
stopped
      the practice.
      Why are you calling init twice?
      If it is just in case the config has chanced, there
is an
      init-and-watch method.
      If it is to combine configurations, the Hash::Merge
module
      can help, and there is a working example somewhere
in the
      archives of this group.
      HTH
      I have a program that configures a basic Log4perl
      config so that I have
      some sane logging until I'm able to read in the
config
      file with the
      final configuration. I'm getting an error when
calling
      Log::Log4perl->init() the second time that I cannot
      seem to track down.
Marc Zampetti
2013-03-18 16:24:49 UTC
Permalink
No, adding Log::Log4perl->reset()
before the second call to Log::log4perl->init() doesn't fix anything. So
far, the only solution is to remove one of the calls to
Log::Log4perl->init().

Marc
Post by Marc Zampetti
So basically the question I have is that I need to reset and
Post by Marc Zampetti
re-configure the logging system at some point after the initial
logging setup. The docs for the init() and init_once() methods suggest
that calling init() a second time will "reset" and "overwrite" the
current configuration, which in this case I want.
Can you try if calling
Log::Log4perl->reset()
before calling init() the second time fixes the problem?
-- -- Mike
Mike Schilli
In the test suite,
Post by Marc Zampetti
I hope that helps.
I don't know the L4p source, but I vaguely recall that
someone, years ago, possibly in the Log4perl docs, said that
the init method was only intended to implement
initialisation, not re-initialisation.
I may be wrong — I can't imagine ever calling init() twice,
though I did occasionally do it when I first started using
the system, there was some now-forgotten issue that stopped
the practice.
Why are you calling init twice?
If it is just in case the config has chanced, there is an
init-and-watch method.
If it is to combine configurations, the Hash::Merge module
can help, and there is a working example somewhere in the
archives of this group.
HTH
I have a program that configures a basic Log4perl
config so that I have
some sane logging until I'm able to read in the config
file with the
final configuration. I'm getting an error when calling
Log::Log4perl->init() the second time that I cannot
seem to track down.
Loading...