c++ - Implementing an orthogonal log level that gets dumped into a socket -


i'm using boost log , want implement log level independent of existing log levels.

this log level activated on-demand, if there listening client connected daemons socket (independent of current configured log level).

is possible implement?

i suspect on-demand functionality can implemented through custom sink either discard, or send data. how integrate rest of logging code?

let's separate goals want achieve. if understand correctly:

  1. you want log records sent through socket process.
  2. only select log records need sent, others need not.
  3. you want enable or disable functionality @ run time.

each of these points can achieved extending or customizing different parts of boost.log. let's see how each of these goals can achieved.

1. create custom sink backend.

boost.log uses sinks process log records. not provide sink sending records on socket, correct in need write one. there tutorial on this. note need write backend, i.e. part sends records. part implements thread synchronization , filtering provided library in form of several frontends, can use custom backend.

the important decision here format in want send log records on network. easiest implement text-based format because can use formatters provided library compose string log record. if need binary format have implement serialization (perhaps, of boost.serialization or library). have extract attribute values log record views in order serialize them binary form suitable sending. we'll attributes in moment.

when sink backend implemented, can select suitable frontend , add sink the logging core. can done once @ application startup, , can done if @ point log records not need sent.

2. mark log records attributes.

any kind of data want put log represented attributes. includes timestamps, severity levels , log message itself. log records collections of values generated attributes, associated attribute names. if want differentiate log records others (in case selectively send them through sink) have mark them distinct attribute. severity levels don't suit because, said, want send records regardless of level.

you can use channels means route of log records new sink. channel attribute (typically, string) can analyzed filters in order block log records sinks , pass others. channels, severity levels , matter other attributes can used form log records pass library. example, here commonly used logger supports both channels , severity levels.

there other ways mark log records. example, can use scoped attributes mark log records made in particular scope attribute. advantage of approach way can mark log records made through logger, without having access logger.

3. configure filters.

as mentioned, in order select log records make sink have set filter sink. filters managed sink frontends, don't have implement in backend. filter check attribute values every log record application emits , pass records satisfy condition. example, can set filter pass records specific value of channel attribute attached. or can set filter return false, disabling logging through sink. can set filters @ time, can modify logging behavior on request. need keep pointer sink available somewhere able set filters when needed.


Comments