libosmocore 1.13.1.1-afb4 Osmocom core library

Files | Functions
Osmocom ringbuffer-backed logging

This adds a log which consist of an in-memory ring buffer. More...

## Files
file | loggingrb.h
file | loggingrb.c
| Ringbuffer-backed logging support code.

## Functions
size_t | log_target_rb_used_size (struct log_target const *target)
| Return the number of log strings in the osmo_strrb-backed target. More...
size_t | log_target_rb_avail_size (struct log_target const *target)
| Return the capacity of the osmo_strrb-backed target. More...
const char * | log_target_rb_get (struct log_target const *target, size_t logindex)
| Return the nth log entry in a target. More...
struct log_target * | log_target_create_rb (size_t size)
| Create a new logging target for ringbuffer-backed logging. More...
static void | _rb_output (struct log_target *target, unsigned int level, const char *log)

## Detailed Description

This adds a log which consist of an in-memory ring buffer.

The idea is that the user can configure his logging in a way that critical messages get stored in the ring buffer, and that the last few critical messages can then always obtained by dumping the ring buffer. It can hence be used as a more generic version of the "show me the last N alarms" functionality.

## Function Documentation

## ◆ _rb_output()

static void _rb_output | ( | struct log_target * | target,
|  | unsigned int | level,
|  | const char * | log
| ) |  |
| static

References osmo_strrb_add(), log_target::rb, and log_target::tgt_rb.

Referenced by log_target_create_rb().

## ◆ log_target_create_rb()

struct log_target * log_target_create_rb | ( | size_t | size | ) |

Create a new logging target for ringbuffer-backed logging.

Parameters

  [in] | size | The capacity (number of messages) of the logging target.

Returns
  A log target in case of success, NULL in case of error.

References _rb_output(), log_target_create(), log_target_destroy(), LOG_TGT_TYPE_STRRB, osmo_strrb_create(), log_target::output, log_target::rb, osmo_strrb::size, log_target::tgt_rb, and log_target::type.

## ◆ log_target_rb_avail_size()

size_t log_target_rb_avail_size | ( | struct log_target const * | target | ) |

Return the capacity of the osmo_strrb-backed target.

Parameters

  [in] | target | The target to search.

Note that this is the capacity (aka max number of messages). It is not the number of unused message slots.

Returns
  The number of log strings in the osmo_strrb-backed target.

References log_target::rb, osmo_strrb::size, and log_target::tgt_rb.

## ◆ log_target_rb_get()

const char * log_target_rb_get | ( | struct log_target const * | target,
|  | size_t | logindex
| ) |  |

Return the nth log entry in a target.

Parameters

  [in] | target | The target to search.
  [in] | logindex | The index of the log entry/error message.

Returns
  A pointer to the nth message, or NULL if logindex is invalid.

References osmo_strrb_get_nth(), log_target::rb, and log_target::tgt_rb.

## ◆ log_target_rb_used_size()

size_t log_target_rb_used_size | ( | struct log_target const * | target | ) |

Return the number of log strings in the osmo_strrb-backed target.

Parameters

  [in] | target | The target to search.

Returns
  The number of log strings in the osmo_strrb-backed target.

References osmo_strrb_elements(), log_target::rb, and log_target::tgt_rb.