---
name: "log_close"
section: "3"
platform: "linux"
package: "arla"
version: "0.36.2-11"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/log_log"
---

# log\_close(3)

provides unified logging

Part of [log\_log(3)](/log_log/3.md).

## NAME

**log\_log**, **log\_vlog**, **log\_open**, **log\_close**, **log\_unit\_init**, **log\_unit\_free**, **log\_set\_mask**, **log\_get\_mask**, **log\_mask2str**, **log\_set\_mask\_str** – provides unified logging

## SYNOPSIS

**#include \<parse\_units.h\>**

**#include \<log.h\>**

**void log\_log**(*Log\_unit \*unit*, *unsigned level*, *const char \*fmt*, *...*);

**void log\_vlog**(*Log\_unit \*unit*, *unsigned level*, *const char \*fmt*, *va\_list args*);

**Log\_method \*log\_open**(*char \*progname*, *char \*fname*);

**void log\_close**(*Log\_method \*method*);

**Log\_unit \*log\_unit\_init**(*Log\_method \*method*, *const char \*name*, *struct units \*lognames*, *unsigned long default\_mask*);

**void log\_unit\_free**(*Log\_method \*method*, *Log\_unit \*unit*);

**void log\_set\_mask**(*Log\_unit \*unit*, *unsigned long mask*);

**unsigned log\_get\_mask**(*Log\_unit \*unit*);

**void log\_mask2str**(*Log\_method \*method*, *Log\_unit \*unit*, *char \*buf*, *size\_t sz*);

**void log\_set\_mask\_str**(*Log\_method \*method*, *Log\_unit \*default\_unit*, *const char \*str*);

## DESCRIPTION

**log\_log** will let you have a unified logging system throu-out your whole project. No more strange errnos like EINVAL returned from libraries since they can print to stderr (not knowing what fd will be connected to fd number 2).

**log\_open**() will open a Log\_method that all Log\_units will log though, Log\_method controls to what device the log is sent. Logging devices, passed in fname, are syslog, /dev/stderr, or a file.

Options can be passes to the subsystem with an extra colon. Valid options are:

syslog\[:pid,no-delay,console,stderr\[:facility\]\]

{/dev/stderr,/file}\[:notime\]

**log\_close**() closeses the Log\_method and assosiated Log\_units.

**log\_unit\_init**() will return a logging unit, that is used by a subsystem.

**log\_unit\_free**() will free a logging unit allocated by **log\_unit\_init**().

**log\_set\_mask**() set the logging mask for a logging unit.

**log\_get\_mask**() get the logging mask for a logging unit.

**log\_mask2str**() convert the longing mask for \`unit' (or all if this is NULL), to a string that can be printed. The string can be parsed by **log\_set\_mask\_str**().

**log\_set\_mask\_str**() will set the mask for \`default\_unit' (or all if this is NULL).

## EXAMPLE

```
#include <parse_units.h>
#include <log.h>
#include <err.h>
enum { A_WARNING = 1, A_DEBUG = 2 };
struct units u_units[] = {
    { "debug",		A_DEBUG },
    { "warning", 	A_WARNING },
    { NULL, 		0 }
};
int
main (int argc, char **argv)
{
    Log_method *m;
    Log_unit *u;
    char buf[1024];
    m = log_open ("log-tester", "/dev/stderr");
    if (m == NULL)
	errx (1, "log_open");
    u = log_unit_init (m, "test-foo", u_units, A_WARNING);
    if (u == NULL)
	errx (1, "log_unit_init");
    log_log (u, A_WARNING, "this should show");
    log_log (u, A_DEBUG, "this should NOT show");
    log_mask2str (m, NULL, buf, sizeof(buf));
    printf ("logmask: %s\n", buf);
    log_close (m);
    return 0;
}
```

## BUGS

Should maybe include a log\_logx version.

## SEE ALSO

[syslog(3)](/syslog/3.md), [syslogd(8)](/syslogd/8.md)
