Files
djhackersdev_bemanitools/src/main/core/log-sink.h
T
icex2 573840aba6 feat: Add core module
This module contains the "core" (API) of
bemanitools which includes an abstraction
layer for threads and logging at this time.

The threads API is very close to what
util/thread already was with some structural
enhancements which make it easier to understand
and work with the API, I hope. Some additional
helpers (*-ext module) support in doing common
tasks, e.g. setting up the thread API with other
modules.

The log(ging) part receives a major overhaul to
address known limitations and issues with the
util/log module:
- Cleaner API layer
- Separate sinks from actual logging engine
- Sinks are composable
- Improved and cleaner compatibility layer
  with AVS logging API

Additional "extensions" (*-ext modules) add
various helper functions for common tasks like
setting up the logging engine with a file and stdout
sink.

The sinks also improved significantly with the file
sink now supporting proper appending and log rotation.
Logging to stdout/stderr supports coloring of log
messages which works across logging engines.

Overall, this refactored foundation is expected to
support future developments and removes known
limitations at the current scale of bemanitools such as:
- Reducing boiler plate code across hooks
- Interop of bemanitools and AVS (and setting the foundation
  for addressing currently missing interop, e.g. for
  dealing with property structures without AVS)
- Addressing performance issues in the logging engine
  due to incorrect interop with AVS
2024-08-14 17:52:59 +02:00

45 lines
1.3 KiB
C

#ifndef CORE_LOG_SINK_H
#define CORE_LOG_SINK_H
#include <stdint.h>
/**
* Write function for a log sink implementation.
*
* Write the given data to your target output destination.
*
* @param ctx Context defined by the implementation when opening the sink.
* @param chars Buffer with text data to log. This can contain partial data of
* a single log line, a full log line terminated by a newline
* character or multiple log lines (each terminated by a newline
* character).
* @param nchars Number of characters to write.
*/
typedef void (*core_log_sink_write_t)(
void *ctx, const char *chars, size_t nchars);
/**
* Close your log sink and cleanup resources
*
* Depending on your implementation, you might want to flush any
* outstanding/buffered data.
*
* @param ctx Context defined by the implementation when opening the sink.
*/
typedef void (*core_log_sink_close_t)(void *ctx);
/**
* Log sink structure.
*
* This must be set-up and populated when opening your log sink implementation.
* The ctx field contains any arbitrary data that you need for your log sink
* to operate, e.g. a file handle, additional buffers etc. Make sure these
* resources are cleaned up upon closing the sink.
*/
struct core_log_sink {
void *ctx;
core_log_sink_write_t write;
core_log_sink_close_t close;
};
#endif