A C++ library for logging very fast and without allocating.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 line
2.6 KiB

  1. #pragma once
  2. #ifdef __cplusplus
  3. #include <cstdint>
  4. #include <cstddef>
  5. #else
  6. #include <stdint.h>
  7. #include <stddef.h>
  8. #endif
  9. #include "sl/strategies.h"
  10. struct sl_buffer_strategy;
  11. struct sl_sink_strategy;
  12. struct sl_overflow_strategy;
  13. struct sl_output_strategy;
  14. #ifdef __cplusplus
  15. namespace sl {
  16. using buffer_strategy = sl_buffer_strategy;
  17. using sink_strategy = sl_sink_strategy;
  18. using overflow_strategy = sl_overflow_strategy;
  19. using output_strategy = sl_output_strategy;
  20. }
  21. #else
  22. typedef struct sl_buffer_strategy sl_buffer_strategy;
  23. typedef struct sl_sink_strategy sl_sink_strategy;
  24. typedef struct sl_overflow_strategy sl_overflow_strategy;
  25. typedef struct sl_output_strategy sl_output_strategy;
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * @brief Constructs a buffer strategy from C
  32. * @param strategy The type of strategy
  33. * @param filename A file describing the strategy, ignored if SL_BUFFER_TYPE is SL_INTERNAL, optional if SL_BUFFER_TYPE is SL_SHARED
  34. * @return a strategy token for building a logger
  35. */
  36. sl_buffer_strategy* sl_create_buffer_strategy(SL_BUFFER_TYPE strategy, char *filename);
  37. /**
  38. * @brief Constructs a sink strategy for how to handle IO in the logger
  39. * @param strategy The type of strategy
  40. * @return a strategy token to build a logger
  41. */
  42. sl_sink_strategy* sl_create_sink_strategy(SL_SINK_IO_TYPE strategy);
  43. /**
  44. * @brief Constructs an overflow strategy for how to handle the edge case of a full buffer
  45. * @param strategy The type of strategy
  46. * @return a strategy token to build a logger
  47. */
  48. sl_overflow_strategy* sl_create_overflow_strategy(SL_ON_SINK_FULL strategy);
  49. /**
  50. * @brief Constructs a strategy that will direct where data is logged and how it will be split
  51. * @param strategy The strategy to use
  52. * @param strategy_parameter Either the amount of hours to keep in the same file, or the file size in kilobytes
  53. * @param output_directory The directory where the logs will be written
  54. * @return a strategy token to build a logger
  55. */
  56. sl_output_strategy* sl_create_output_strategy(SL_ROLL_LOGS strategy, uint64_t strategy_parameter, char* output_directory);
  57. /**
  58. * @brief Constructs and registers a logger, readily available immediately
  59. * @param internal_id The ID with which you want to refer to the logger to access it as fast as possible
  60. * @param external_id The ID which will be part of the logs filename
  61. * @param strategies Collect the 4 tokens and reunite them into the hero's sword that will slay every other logger
  62. */
  63. void sl_register_logger(int internal_id, char* external_id, sl_buffer_strategy*, sl_sink_strategy*, sl_overflow_strategy*, sl_output_strategy*);
  64. #ifdef __cplusplus
  65. }
  66. #endif