Skip to content
Mateusz Piotrowski edited this page Aug 4, 2016 · 1 revision

Add pjdlog to your project

  1. Copy /contrib/openbsm/bin/auditdistd/pjdlog.* to your project.

  2. Add pjdlog.c to your make file (probably something like SRCS+= pjdlog.c should work).

  3. You'll probably be facing

     .../pjdlog.h:40:10: fatal error:
         'compat/compat.h' file not found
     #include <compat/compat.h>
              ^
     1 error generated.
     *** Error code 1
    
     Stop.
    

when you try to run make.

If so then add something like

OPENBSMDIR=${.CURDIR}/../../contrib/openbsm
CFLAGS+=-I${OPENBSMDIR} -I${OPENBSMDIR}/sys

to you Makefile (adjust the paths to fit your project).

  1. Add #include "pjdlog.h" to your source and you're ready to go.

Usage

Debug level

The lower the debug log level is the more it is important.

Example 1

pjdlog_debug_set(1);
pjdlog_debug(1, "a");
pjdlog_debug(2, "b");

prints

a

Example 2

pjdlog_debug_set(2);
pjdlog_debug(1, "a");
pjdlog_debug(2, "b");

prints

a

b

Simple usage example

#include "pjdlog.h"

int main() {
    // Initialize pjdlog to log into stderr.
    pjdlog_init(PJDLOG_MODE_STD);

    // Enable debug logging. There will be only one level of debug messages.
    pjdlog_debug_set(1);

    // Log.
    pjdlog_debug(1, "aaa!!!111");

    // Close pjdlog.
    pjdlog_fini();
}