xaizek / vifm-pdcurses (License: mostly public domain) (since 2019-03-20)
PDCurses 3.4 with vifm-specific patches applied (a couple were upstreamed)
<root> / pdcurses / debug.c (95dc7d445f152f30c8c0f793d8970bfcf9519e58) (1,935B) (mode 100644) [raw]
/* Public Domain Curses */

#include <curspriv.h>

RCSID("$Id: debug.c,v 1.7 2008/07/13 16:08:18 wmcbrine Exp $")

/*man-start**************************************************************

  Name:                                                         debug

  Synopsis:
        void traceon(void);
        void traceoff(void);
        void PDC_debug(const char *, ...);

  Description:
        traceon() and traceoff() toggle the recording of debugging 
        information to the file "trace". Although not standard, similar 
        functions are in some other curses implementations.

        PDC_debug() is the function that writes to the file, based on 
        whether traceon() has been called. It's used from the PDC_LOG() 
        macro.

  Portability                                X/Open    BSD    SYS V
        traceon                                 -       -       -
        traceoff                                -       -       -
        PDC_debug                               -       -       -

**man-end****************************************************************/

#include <string.h>
#include <sys/types.h>
#include <time.h>

bool pdc_trace_on = FALSE;

void PDC_debug(const char *fmt, ...)
{
    va_list args;
    FILE *dbfp;
    char hms[9];
    time_t now;

    if (!pdc_trace_on)
        return; 

    /* open debug log file append */

    dbfp = fopen("trace", "a");
    if (!dbfp)
    {
        fprintf(stderr,
            "PDC_debug(): Unable to open debug log file\n");
        return;
    }

    time(&now);
    strftime(hms, 9, "%H:%M:%S", localtime(&now));
    fprintf(dbfp, "At: %8.8ld - %s ", (long) clock(), hms);

    va_start(args, fmt);
    vfprintf(dbfp, fmt, args);
    va_end(args);

    fclose(dbfp);
}

void traceon(void)
{
    PDC_LOG(("traceon() - called\n"));

    pdc_trace_on = TRUE;
}

void traceoff(void)
{
    PDC_LOG(("traceoff() - called\n"));

    pdc_trace_on = FALSE;
}
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm-pdcurses

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm-pdcurses

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master