libbclog 0.2.1

A betterC structured logger

To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:


This is an extremely fast, allocationless, thread-safe*, betterC, structured logging library that supports custom log sinks.

(* Currently only on Posix since I need to setup a dev env for Windows. Also maybe not even on Posix since I haven't properly tested it yet.)


  • Thread-Safe (see disclaimer)
  • Allocationless (except for whatever libc does internally)
  • Easy to use
  • Written with -betterC in mind
  • Supports custom logging sinks
  • Provides a Console sink
  • Provides a File sink
  • Provides a Filter sink to wrap around other sinks
  • Structured (built-in sinks output as JSON)
  • Helper function to output JSON into an output sink

Quick Start

Add this library via dub/meson/your preferred method.

import libbc.log;

struct Client
    string ip;
    ushort port;

void main()
    // Logger is not copyable, so make it global/put it on the heap.
    Logger!(, // Or .yes for a thread-safe logger.
        Sink!("file", FileSink),
        Sink!("console", ConsoleSink)
    ) logger;"log.log"); // File loggers have to be opened first.

    logger.trace("This is a trace");
    logger.debug_("Debug This Bug!");"This one has fields!", field!"service"("login"), field!"client"(Client("", 420)));

    logger.warning("404 Life not found");
    logger.error("Not enough cheese");
    logger.fatal("Dog went 5 seconds without attention");


{"level": "trace", "message": "This is a trace", "file": "source/libbc/log/core.d", "func": "libbc.log.core.__unittest_L237_C1", "line": 255, "timestamp": 1636142080}
{"level": "debug_", "message": "Debug This Bug!", "file": "source/libbc/log/core.d", "func": "libbc.log.core.__unittest_L237_C1", "line": 256, "timestamp": 1636142080}
{"level": "info", "message": "This one has fields!", "file": "source/libbc/log/core.d", "func": "libbc.log.core.__unittest_L237_C1", "line": 258, "timestamp": 1636142080, "service": "login", "client": {"ip": "", "port": 420}}
{"level": "warning", "message": "404 Life not found", "file": "source/libbc/log/core.d", "func": "libbc.log.core.__unittest_L237_C1", "line": 260, "timestamp": 1636142080}
{"level": "error", "message": "Not enough cheese", "file": "source/libbc/log/core.d", "func": "libbc.log.core.__unittest_L237_C1", "line": 261, "timestamp": 1636142080}
{"level": "fatal", "message": "Dog went 5 seconds without attention", "file": "source/libbc/log/core.d", "func": "libbc.log.core.__unittest_L237_C1", "line": 262, "timestamp": 1636142080}

Filtering by log level

Simply wrap any sinks inside of FilterByLogLevelSink:

void main()
        Sink!("console", FilterByLogLevelSink!ConsoleSink)
    ) logger;

    logger.console.minLogLevel = LogLevel.debug_;
    logger.console.maxLogLevel = LogLevel.warning;
    // Use logger.console.sink to access the underlying sink if needed.

    logger.trace("This won't show up");
    logger.fatal("Neither will this");"But this will");


As is custom with benchmarks, take everything with a grain of salt.

There are currently two tests:

  • hello_world - A simple"hello world")
  • 6_fields - Prints out 6 fields, all being different types for JSON serialisation

Across three sinks:

  • console - Uses printf
  • null - Performs serialisation, but doesn't output it anywhere
  • file - Outputs to a file

Result set 1 - Intel(R) Celeron(R) CPU N3350 @ 1.10GHz

Units: ns = nano seconds and us = micro seconds.

console hello_world1000004189741418977437841424584.189774378
null hello_world1000002830283967925790.028396792
file hello_world100000248222482764512974870.248276451
console 6_fields1000009001289900127320889628599.001273208
null 6_fields10000057305736736441490.057367364
file 6_fields100000904189041639878640920.904163987


[ ] Make Windows thread-safe

[ ] Add more sinks

[ ] Add threading tests

[ ] Add a log rotater sink

[ ] ???

[x] profit

  • Bradley Chatha
libbcfmt, libbcds
0.2.1 2021-Nov-08
0.2.0 2021-Nov-06
0.1.0 2021-Nov-05
~master 2022-Feb-21
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 0 downloads total

Short URL: