libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
log.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include "log.h"

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200112L
#define LOG_STATE_UNINITIALIZED   0
#define LOG_STATE_INITIALIZING   1
#define LOG_STATE_READY   2
#define LOG_LEVEL_NONE   (-1)
#define LOG_STACK_BUFFER_SIZE   1024

Functions

static int log_state_claim (void)
static long log_state_load (void)
static void log_state_store (long value)
static int log_strcasecmp (const char *a, const char *b)
static void log_init (void)
 Resolves the logging configuration from the environment, exactly once per process.
static const char * log_short_path (const char *file)
 Strips the build-machine directory from FILE, keeping the path below src/ if present.
static int log_timestamp (char *buf, size_t size)
void aaru_log_write (int level, const char *file, int line, const char *func, const char *fmt,...)
 Writes one log line.
void aaru_log_reset (void)

Variables

static volatile long log_state = 0
static FILE * log_stream = NULL
static int log_level = 1

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200112L

Definition at line 20 of file log.c.

◆ LOG_LEVEL_NONE

#define LOG_LEVEL_NONE   (-1)

Definition at line 41 of file log.c.

Referenced by log_init().

◆ LOG_STACK_BUFFER_SIZE

#define LOG_STACK_BUFFER_SIZE   1024

Definition at line 43 of file log.c.

Referenced by aaru_log_write().

◆ LOG_STATE_INITIALIZING

#define LOG_STATE_INITIALIZING   1

Definition at line 38 of file log.c.

Referenced by log_state_claim().

◆ LOG_STATE_READY

#define LOG_STATE_READY   2

Definition at line 39 of file log.c.

Referenced by aaru_log_reset(), and log_init().

◆ LOG_STATE_UNINITIALIZED

#define LOG_STATE_UNINITIALIZED   0

Definition at line 37 of file log.c.

Referenced by aaru_log_reset(), and log_state_claim().

Function Documentation

◆ aaru_log_reset()

void aaru_log_reset ( void )

◆ aaru_log_write()

void aaru_log_write ( int level,
const char * file,
int line,
const char * func,
const char * fmt,
... )

Writes one log line.

Called through the TRACE and FATAL macros in log.h.

The whole line is formatted into a buffer and emitted with a single fwrite(), which stdio locks per call, so lines from concurrent threads do not interleave.

Definition at line 173 of file log.c.

References AARU_LOG_FATAL, aaru_log_write(), log_init(), log_level, log_short_path(), LOG_STACK_BUFFER_SIZE, log_stream, and log_timestamp().

Referenced by aaru_log_write().

◆ log_init()

void log_init ( void )
static

Resolves the logging configuration from the environment, exactly once per process.

AARUFORMAT_LOG_LEVEL selects "trace" (default), "fatal" or "none". AARUFORMAT_LOG_FILE names a file to append to; if unset or unopenable, stderr is used.

Definition at line 93 of file log.c.

References AARU_LOG_FATAL, AARU_LOG_TRACE, log_init(), log_level, LOG_LEVEL_NONE, log_state_claim(), log_state_load(), LOG_STATE_READY, log_state_store(), log_strcasecmp(), and log_stream.

Referenced by aaru_log_write(), and log_init().

◆ log_short_path()

const char * log_short_path ( const char * file)
static

Strips the build-machine directory from FILE, keeping the path below src/ if present.

Definition at line 130 of file log.c.

References log_short_path().

Referenced by aaru_log_write(), and log_short_path().

◆ log_state_claim()

int log_state_claim ( void )
static

Definition at line 64 of file log.c.

References log_state, log_state_claim(), LOG_STATE_INITIALIZING, and LOG_STATE_UNINITIALIZED.

Referenced by log_init(), and log_state_claim().

◆ log_state_load()

long log_state_load ( void )
static

Definition at line 70 of file log.c.

References log_state, and log_state_load().

Referenced by aaru_log_reset(), log_init(), and log_state_load().

◆ log_state_store()

void log_state_store ( long value)
static

Definition at line 71 of file log.c.

References log_state, and log_state_store().

Referenced by aaru_log_reset(), log_init(), and log_state_store().

◆ log_strcasecmp()

int log_strcasecmp ( const char * a,
const char * b )
static

Definition at line 74 of file log.c.

References log_strcasecmp().

Referenced by log_init(), and log_strcasecmp().

◆ log_timestamp()

int log_timestamp ( char * buf,
size_t size )
static

Definition at line 149 of file log.c.

References log_timestamp().

Referenced by aaru_log_write(), and log_timestamp().

Variable Documentation

◆ log_level

int log_level = 1
static

Definition at line 47 of file log.c.

Referenced by aaru_log_reset(), aaru_log_write(), and log_init().

◆ log_state

volatile long log_state = 0
static

Definition at line 45 of file log.c.

Referenced by log_state_claim(), log_state_load(), and log_state_store().

◆ log_stream

FILE* log_stream = NULL
static

Definition at line 46 of file log.c.

Referenced by aaru_log_reset(), aaru_log_write(), and log_init().