eggheads / eggdrop

The Eggdrop IRC Bot
GNU General Public License v2.0
501 stars 84 forks source link

Missing debug log #627

Open michaelortmann opened 6 years ago

michaelortmann commented 6 years ago

Missing debug log when eggdrop is startet with ./eggdrop -nt

its missing from console until console +d can be set, which is possible only after eggdrop is fully loaded console flags for -HQ are not saved to userfile, because -HQ is not saved.

and its missing from log file until eggdrop does "use_stderr = 0;" in main.c i set +d for logfile in eggdrop.conf

my initial problem was that i would like to see the debug log of tls.c:ssl_init() when i start eggdrop with -nt

is this fixable? at least for console for start with -nt? or should we move the call to ssl_init() after "use_stderr = 0;"?

after some more analysis, i thought i could add LOG_DEBUG to EGG_BG_CONMASK in main.h its hardcoded, but i could live with it but its also too late: dcc[term_z].u.chat->con_flags = conmask | EGG_BG_CONMASK; is executed also only after ssl_init(), and even after "use_stderr = 0;"

my temporary solution is to replace line: else if ((type & LOG_MISC) && use_stderr) { with: else if (((type & LOG_MISC) || (type & LOG_DEBUG)) && use_stderr) { in misc.c:putlog()

but we still need a good permanent solution to see LOG_DEBUG in console and/or logfile from the start of eggdrop -nt by default or opt in

Maybe whilefixing #658 i found the cause:

misc.c:

  if (!backgrd && !con_chan && !term_z)                                          
    dprintf(DP_STDOUT, "%s", out);  

Shouldn't that read term_z instead of !term_z ?

michaelortmann commented 5 years ago

set console in eggdrop.conf .store etc do not solve this issue.

Cizzle commented 5 years ago

Shouldn't that read term_z instead of !term_z ?

No, you'll get every logmessage then: those you haven't set with consoleflags and those you have will even be double. You're at the right spot though for any mod, though it should be evaluated what the best way would be.

michaelortmann commented 5 years ago

1. With the now "dead" debug log activated a start of eggdrop would look like:

$ ./eggdrop -nt
[03:42:38] LANG: Language loaded: english
[03:42:38] LANG: Section loaded: core
[03:42:38] LANG: 390 messages of 431 lines loaded from ./language/core.english.lang
[03:42:38] LANG: 390 adds, 0 updates to message table

Eggdrop v1.8.3+sendfprint (C) 1997 Robey Pointer (C) 2010-2018 Eggheads
[03:42:38] Allocated bind table unld (flags 1)
[03:42:38] Allocated bind table time (flags 1)
[03:42:38] Allocated bind table cron (flags 1)
[03:42:38] Allocated bind table note (flags 0)
[...]

2. Why is eggdrop printing early LOG_MISC to stderr? What is the intention?

putlog(LOG_MISC, "*", "=== %s: %d channels, %d users.",                        
[...]
use_stderr = 0;               /* Stop writing to stderr now */

See also https://github.com/eggheads/eggdrop/blob/develop/src/misc.c#L632

The "intention" of early log is unclear.

michaelortmann commented 4 years ago

After some more digging...

  1. Late in startup eggdrop switches to using conmask = console setting from eggdrop.conf
  2. Early in startup this is not available obviously.

Problem is, eggdrops code has putlog(MISC) and putlog(DEBUG) but the user has no control over log levels until the config file is read.

The conmask from eggdrop.conf is not read before main() calls chanprog().

  1. So there is no good solution to set log levels before eggdrop does read the config file, yet. We need to add such mechanism. I propose another command line parameter. Its not that complicated, because we probably only want to focus on the DEBUG console flag.

The command line parameter could be "-d" and add LOG_DEBUG to conflags before conflags is re-initialized within eggdrops startup.

  1. There is also a bug in putlog(), and the following patch would solve it:
-  else if ((type & LOG_MISC) && use_stderr) {
+  else if ((type & (conmask | EGG_BG_CONMASK)) && use_stderr) {

So, what we wanna do in general for fixing this issue is: Taking care of proper conmask setting from the very beginning of eggdrop (command line argument for ./eggdrop start) to the switch to console setting from eggdrop.conf. The putlog() patch can be independent and could be applied right now.