Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug_level/debug_file options #448

Closed
wants to merge 0 commits into from
Closed

Conversation

sileht
Copy link
Contributor

@sileht sileht commented Mar 2, 2017

  • What does this PR do?

This change allows to change debug_level and debug_file on the fly.

  • Are there points in the code the reviewer needs to double check?

We can't really debug the early startup of mutt with these new options.

  • Why was this PR needed?

To solve #445

Closes #445

@sileht
Copy link
Contributor Author

sileht commented Mar 2, 2017

Does the init.h options documentation are enough for this advanced stuff (they are appended at the end of manual), or should I create a new section in the manual ?

@gahr
Copy link
Member

gahr commented Mar 2, 2017

I think we should be consistent with respect to log rotation. In your current approach:

  • if debug_file is not set, the default ~/.muttdebug.%d is used and rotated
  • if debug_file is set, no rotation happen

Wouldn't it be acceptable to have a .%d appended automatically and rotation happening every time the debug is re-initialized?

If we proceed like this, you could have DebugFile default to "~/.muttdebug" and avoid the need for a second debugfilepath variable. This one also leaks memory, although it's not too severe a problem.

@sileht
Copy link
Contributor Author

sileht commented Mar 2, 2017

I have hesitated to do append the '%d' too, so if other agree, I will do it.

Copy link
Contributor

@guyzmo guyzmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, there's one error that breaks compilation with debug disabled, that shall be fixed ☺

Then I agree with @gahr, the log rotate logic should be applied no matter what, if only to make it less likely to overwrite an existing log file.

I believe an environment variable and/or CLI argument should be used in complement of the setting value for setting up target of startup logs.

A timestamp should be written at the start of any given log file (not directly related to the PR, but as you're at it 😉)

init.c Outdated
@@ -2336,6 +2403,8 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
strfcpy (scratch, tmp->data, sizeof (scratch));
mutt_expand_path (scratch, sizeof (scratch));
*((char **) MuttVars[idx].data) = safe_strdup (scratch);
if (mutt_strcmp (MuttVars[idx].option, "debug_file") == 0)
restart_debug ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build is broken, certainly because when DEBUG is not defined, this line cannot compile.

https://travis-ci.org/neomutt/neomutt/builds/206916932#L483

init.c Outdated
{
if (*ptr < 0)
*ptr = 0;
restart_debug ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same.

@sileht
Copy link
Contributor Author

sileht commented Mar 2, 2017

timestamps are already added by mutt_debug()

@sileht
Copy link
Contributor Author

sileht commented Mar 14, 2017

@guyzmo all your points have been fixed.

init.c Outdated
safe_fclose(&debugfile);
}

memcpy(&debuglevel, &DebugLevel, sizeof(int));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debuglevel = DebugLevel ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obviously. done.

@gahr
Copy link
Member

gahr commented Mar 15, 2017

I'm not sure it's wise to restart debug upon a change in debug_level. Why is that needed?

@sileht
Copy link
Contributor Author

sileht commented Mar 28, 2017

@gahr I have added new logic to not restart debug when just debug_level is changed.

Copy link
Member

@gahr gahr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@flatcap flatcap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks nice, but a simple use case doesn't work: setting a different log file/level in muttrc.

set debug_file = "~/logs/muttdebug"
set debug_level = 3

Now run, mutt -d2

Mutt creates the file ~/.muttdebug0 containing a line: "... debugging at level 2"

Within mutt:

  • set ?debug_file replies ~/logs/muttdebug
  • set ?debug_level replies 3

@sileht
Copy link
Contributor Author

sileht commented Mar 30, 2017

@flatcap that was just a logging issue, when the level change nothing was printed, I fixed that.

Also in current implementation, muttrc is loaded after the debug is started, so "set devel_level = 3" will override any mutt -d option.

@flatcap
Copy link
Member

flatcap commented Mar 30, 2017

OK, that's better.

muttrc is loaded after the debug is started

Hmm... Is that what we want? I'd expect the command line to have a higher priority than the config file.
(I suppose ideally, we'd have a debugfile command line option too)

ATM, if I run mutt -d 2 then mutt creates ~/muttdebug0 before it reads the set debug_file line in my config. I can't prevent it creating that file.

@sileht
Copy link
Contributor Author

sileht commented Mar 31, 2017 via email

@sileht sileht force-pushed the sileht/debug branch 3 times, most recently from 48f03ff to 9d672bb Compare March 31, 2017 09:55
@flatcap
Copy link
Member

flatcap commented Mar 31, 2017

I have kept that to allow to debug the init as earlier as possible, especially to have the muttrc parsing

Ah, I see.


<thinking aloud>

Hmm... does the file parsing actually have any debugging?
Aren't the errors just printed to stderr?

NeoMutt/20170306 (1.8.0) debugging at level 2
getdnsdomainname(): flatcap.org
Reading configuration file '/home/mutt/.muttrc'.
Reading configuration file '/home/mutt/.mutt/lists.rc'.
In mutt_reflow_windows
Reading configuration file '/home/mutt/.mutt/alternates.rc'.
Reading configuration file '/home/mutt/.mutt/crypto.rc'.
Reading configuration file '/home/mutt/.mutt/sidebar-dev.rc'.
In mutt_reflow_windows
In mutt_reflow_windows
In mutt_reflow_windows
Reading configuration file '/home/mutt/.mutt/imap.rc'.
Reading configuration file '/home/mutt/.mutt/mailbox.rc'.
Reading configuration file '/home/mutt/.mutt/colours-dev.rc'.
Reading configuration file '/home/mutt/.mutt/status-color.rc'.
Reading configuration file '/home/mutt/.muttrc.local'.
NeoMutt/20170306 (1.8.0) stop debugging 

Could we do something like the linux kernel at startup? It stores its messages in a ring buffer, that gets dumped as soon as there's a tty.
Hmm... too complicated and if mutt crashes nothing will get logged.

</thinking>


So to resume my next version:

Great! Thanks.

@flatcap
Copy link
Member

flatcap commented May 12, 2017

Merged in 40f81d1. Thanks.

@sileht sileht deleted the sileht/debug branch November 16, 2018 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants