• Stars
    star
    2,472
  • Rank 17,853 (Top 0.4 %)
  • Language
    C
  • License
    MIT License
  • Created about 7 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple logging library implemented in C99

log.c

A simple logging library implemented in C99

screenshot

Usage

log.c and log.h should be dropped into an existing project and compiled along with it. The library provides 6 function-like macros for logging:

log_trace(const char *fmt, ...);
log_debug(const char *fmt, ...);
log_info(const char *fmt, ...);
log_warn(const char *fmt, ...);
log_error(const char *fmt, ...);
log_fatal(const char *fmt, ...);

Each function takes a printf format string followed by additional arguments:

log_trace("Hello %s", "world")

Resulting in a line with the given format printed to stderr:

20:18:26 TRACE src/main.c:11: Hello world

log_set_quiet(bool enable)

Quiet-mode can be enabled by passing true to the log_set_quiet() function. While this mode is enabled the library will not output anything to stderr, but will continue to write to files and callbacks if any are set.

log_set_level(int level)

The current logging level can be set by using the log_set_level() function. All logs below the given level will not be written to stderr. By default the level is LOG_TRACE, such that nothing is ignored.

log_add_fp(FILE *fp, int level)

One or more file pointers where the log will be written can be provided to the library by using the log_add_fp() function. The data written to the file output is of the following format:

2047-03-11 20:18:26 TRACE src/main.c:11: Hello world

Any messages below the given level are ignored. If the library failed to add a file pointer a value less-than-zero is returned.

log_add_callback(log_LogFn fn, void *udata, int level)

One or more callback functions which are called with the log data can be provided to the library by using the log_add_callback() function. A callback function is passed a log_Event structure containing the line number, filename, fmt string, va printf va_list, level and the given udata.

log_set_lock(log_LockFn fn, void *udata)

If the log will be written to from multiple threads a lock function can be set. The function is passed the boolean true if the lock should be acquired or false if the lock should be released and the given udata value.

const char* log_level_string(int level)

Returns the name of the given log level as a string.

LOG_USE_COLOR

If the library is compiled with -DLOG_USE_COLOR ANSI color escape codes will be used when printing.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

More Repositories

1

lite

A lightweight text editor written in Lua
Lua
7,254
star
2

microui

A tiny immediate-mode UI library
C
3,124
star
3

json.lua

A lightweight JSON library for Lua
Lua
1,734
star
4

dyad

Asynchronous networking for C
C
1,432
star
5

fe

A tiny, embeddable language implemented in ANSI C
C
1,262
star
6

lume

Lua functions geared towards gamedev
Lua
945
star
7

classic

Tiny class module for Lua
Lua
799
star
8

lovedos

A framework for making 2D DOS games in Lua
C
659
star
9

map

A type-safe hash map implementation for C
C
553
star
10

vec

A type-safe dynamic array implementation for C
C
426
star
11

microtar

A lightweight tar library written in ANSI C
C
423
star
12

flux

A fast, lightweight tweening library for Lua
Lua
354
star
13

lite-plugins

Plugins for the lite text editor
Lua
342
star
14

ini

A tiny ANSI C library for loading .ini config files
C
315
star
15

log.lua

A tiny logging module for Lua
Lua
287
star
16

lovebird

A browser-based debug console for LÖVE
Lua
282
star
17

lurker

Auto-swaps changed Lua files in a running LÖVE project
Lua
268
star
18

kit

A tiny library for making small games with big pixels
C
240
star
19

aq

A lightweight framework for creating audio toys
C
236
star
20

uuid4

A tiny C library for generating uuid4 strings
C
214
star
21

sandbird

A tiny embeddable HTTP server written in C89
C
169
star
22

cmixer

Portable ANSI C audio mixer for games
C
168
star
23

aria

A tiny, embeddable lisp-shaped language implemented in C89
C
166
star
24

sfd

A small C library for opening a file dialog
C
165
star
25

juno

Framework for making 2D games with chunky pixels in Lua
C
160
star
26

tick

Lua module for delaying function calls
Lua
123
star
27

autobatch

Small LÖVE module to automate the use of SpriteBatches
Lua
103
star
28

lite-colors

Colors themes for the lite text editor
Lua
99
star
29

dmt

Dynamic memory tracker for C
C
99
star
30

cembed

A small utility for embedding files in a C header
C
90
star
31

doq

A small tool for creating single-file html documents
C
82
star
32

lovebpm

A LÖVE library for syncing events to the BPM of an audio track
Lua
76
star
33

coil

A tiny cooperative threading module for Lua
Lua
71
star
34

shash

A simple, lightweight spatial hash for Lua
Lua
64
star
35

console

A console plugin for the lite text editor
Lua
57
star
36

atlas

A small utility for generating a texture atlas
C
41
star
37

rxi.github.io

HTML
17
star
38

gifwriter

A Nim library for writing animated GIFs
C
17
star
39

cmixer_sdl2-nim

Tiny Nim library for using cmixer with sdl2
Nim
3
star
40

cmixer-nim

Nim wrapper for cmixer, A lightweight audio mixer for games
C
3
star
41

crate

2
star