aboutsummaryrefslogtreecommitdiffstats
path: root/man/el_option.3
blob: f2fdfa94dc09ce6bb7b8cc9a78827f8f518a8041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
.TH "el_option" "3" "10 June 2019 (v9999)" "bofc.pl"
.SH NAME
.PP
.B el_option
- sets optional configuration of the logger
.SH SYNOPSIS
.PP
.B #include <embedlog.h>
.PP
.BI "int el_option(enum el_option " option ", " ... ")"
.br
.B const struct el *el_get_el(void)
.br
.BI "int el_ooption(struct el *" el ", \
enum el_option " option ", " ... ")"
.SH DESCRIPTION
.PP
.BR el_option (3)
allows user to configure logger's internal el object, to tune logging to users
needs.
.PP
.BR el_get_el (3)
allows user to get pointer to global embedlog object - that is used by all
embedlog functions that don't accept
.I el
object - to directly read its fields.
.SH OPTIONS
.PP
Below is a list of
.I option
that can be configured.
Value inside parenthesis determines argument types of variadic arguments
.I ...
.PP
.BI "EL_LEVEL (" enum " " el_level " level)"
.RS
.   B EL_LEVEL
sets what the current logging level shall be.
Altough it accepts
.   B enum el_level
type, this can be whatever number from range <0, 7>.
The higher the level, the lower priority of the message.
All messages that have lower priority (higher number) then currently set
.   I level
will not be printed.
There are 8 predefined levels, sorted by priority (highest first):
.   PP
.   RS
.       B EL_FATAL,
.       br
.       B EL_ALERT,
.       br
.       B EL_CRIT,
.       br
.       B EL_ERROR,
.       br
.       B EL_WARN,
.       br
.       B EL_NOTICE,
.       br
.       B EL_INFO,
.       br
.       B EL_DBG
.   RE
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
specified
.       I level
is invalid (bigger than EL_DBG).
.       RE
.   RE
.RE
.PP
.BI "EL_OUT (" enum " " el_output " outputs)"
.RS
.   B EL_OUT
simply sets to what
.IR outputs .
logs will be printed to with any of the printing
function.
User can enable as many outputs as he desires - it can be all inputs or even
none (if one wants to surpress logging for some time).
To enable multiple outputs join values with
.   B or
operator (
.   B |
).
.   PP
Currently following
.I outputs
can be enabled.
.   PP
.   B EL_OUT_STDERR
.   RS
Messages will be printed to standard error output
.   RE
.   PP
.   B EL_OUT_STDOUT
.   RS
Messages will be printed to standard output
.   RE
.   PP
.   B EL_OUT_SYSLOG
.   RS
Messages will be sent to syslog facility. This requires system with implemented
POSIX.1-2001 and any syslog daemon
.   RE
.   PP
.   B EL_OUT_FILE
.   RS
Messages will be printed to file.
To work user should set output file with
.       BR EL_FPATH .
Log rotation can be configured with
.       B EL_FROTATE_NUMBER
and
.       B EL_FROTATE_SIZE
options.
.   RE
.   PP
.   B EL_OUT_NET
.   RS
Messages shall be printed to external server.
This requires BSD Sockets to be enabled on the clients system, and listening
server.
(TODO Not implemented yet)
.   RE
.   PP
.   B EL_OUT_TTY
.   RS
Prints messages directly to configured serial console.
Apart from setting this, user should also configure device and speed with
.   BR EL_TTY_DEV .
.   RE
.   PP
.   B EL_OUT_ALL
.   RS
Enables all supported outputs at once
.   RE
.   PP
.   B EL_OUT_NONE
.   RS
Disables every output - logs won't be printed at all
.   RE
.   PP
.   B EL_OUT_CUSTOM
.   RS
Enables custom function to be called on log print.
Pointer to custom function needs to be set with
.       B EL_CUSTOM_PUTS
option.
.   RE
.   PP
Many of the outputs can be configured for special needs, and some of them need
mandatory configuration.
For information about output configuration see proper option description
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Specified
.           I output
is invalid
.       RE
.   RE
.   PP
.   RS
.       B ENODEV
.       RS
Specified
.I          output
is not implemented on current system (support was not compiled into library)
.       RE
.   RE
.RE
.PP
.BI "EL_PREFIX (" const " " char " " * "prefix)"
.RS
You can configure logger to add
.   I prefix
to every message you print.
.   I prefix
will be printed between log level info "i/" and you message.
No spaces are added.
If you set your
.   I prefix
to simple
.   BR PREFIX ,
printed message will be
.   BR "i/PREFIXmy log message" ,
so you might want to add space there.
If
.   I prefix
is bigger than
.   B EL_PREFIX_LEN
prefix will be truncated.
To disable prefixing, simply set
.   I prefix
to
.   BR NULL .
.RE
.PP
.BI "EL_COLORS (" int " colors)"
.RS
If this is set to 1, output will be enriched with ANSI colors depending on the
message severity.
This option needs terminal supporting colors.
You can store messages with colors to file, and then read them with colors on
color-enabled terminal.
If this is set to 0, no colors will be added.
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input argument is different than 1 or 0
.       RE
.   RE
.RE
.PP
.BI "EL_TS (" enum " " el_option_timestamp " timestamp)"
.RS
Allows timestamp to be added to each log message. Possible values for
.I timestamp
are:
.   PP
.   B EL_TS_OFF
.   RS
Timestamp will not be added to messages
.   RE
.   PP
.   B EL_TS_SHORT
.   RS
Short timestamp will be added to log in format
.       B [1503661223.537631]
.   RE
.   PP
.   B EL_TS_LONG
.   RS
Long timestamp will be added to log in format
.       B [2017-08-25 11:40:23.537651]
.   RE
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input argument is invalid
.       RE
.       PP
.       B ENOSYS
.       RS
Timestamp support was not compiled in and setting this option is disabled.
.       RE
.   RE
.RE
.PP
.BI "EL_TS_TM (" enum " " el_option_timestamp_timer " timer)"
.RS
Sets the timer source for the timestamp print.
.   PP
.   B EL_TS_TM_CLOCK
.   RS
Library will use value from
.       BR clock ()
function.
With this clock precission varies from 10^-3[s] to 10^-9[s].
On POSIX systems, this clock has precision of 10^-6[s].
This timer has a lot drawbacks, time value is unspecified at the beggining of
the program, timer is not incremented when thread is sleeping, timer will
overlap eventually (on 32bit systems with POSIX it takes around 72 minutes for
the clock to overlap).
On the other hand this is the most precise clock for pure c89 systems without
POSIX.
.   RE
.   PP
.   B EL_TS_TM_TIME
.   RS
Time is taken from
.       BR time ()
function.
This returns current wall clock of the system, it's precision is very low
(1[s]), but it's pure c89 and it is good for logging low frequent messages.
This clock is susceptible to unexpected time change (from NTP or by root
itself).
.   RE
.   PP
.   B EL_TS_TM_REALTIME
.   RS
Time is taken from
.       BR clock_gettime ()
using
.       B CLOCK_REALTIME
clock.
This required system with POSIX.1-2001.
This time returns current system wall clock, but it's precision is much higher
than
.       B EL_TS_TM_TIME
clock (depending on system it can vary from 10^-3[s] up to even 10^-9[s]).
Just like it is with
.       B EL_TS_TM_TIME
this timestamp can jump forward of backward if it is changed in the system.
.   RE
.   PP
.   B EL_TS_TM_MONOTONIC
.   RS
This clock is similar to
.       B EL_TS_TM_REALTIME
but it shows time from unspecified time and is not affected by time change
(it can still be altered with
.       BR adjtime ()
or NTP)
.   RE
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input argument is invalid
.       RE
.       PP
.       B ENODEV
.       RS
Specified timer source was not compiled in and is not available
.       RE
.   RE
.RE
.PP
.BI "EL_TS_FRACT (" enum " " el_option_timestamp_fraction " fraction)
.RS
This option controls how to display fractions of seconds.
If high resolution is not needed or not supported, it's best to set this to
lowest resolution possible.
Table will show exacly what this is about.
Example uses long timestamp, interesting part is after date after dot '.'.
.PP
.nf
    +-----------------+-------------------------------+
    |      value      |  resulting timestamp string   |
    +-----------------+-------------------------------+
    | EL_TS_FRACT_OFF | 2018-04-17 22:02:57           |
    | EL_TS_FRACT_MS  | 2018-04-17 22:02:57.070       |
    | EL_TS_FRACT_US  | 2018-04-17 22:02:57.070518    |
    | EL_TS_FRACT_NS  | 2018-04-17 22:02:57.070518782 |
    +-----------------+-------------------------------+
.fi
.RE
.PP
.BI "EL_PRINT_LEVEL (" int " print)"
.RS
If this is set to 1, each log will have log level information prefix in format
"l/" where 'l' is first character of level message is printed with, for example:
.   PP
.   RS
c/this is critical message
.       br
n/this is just a notice
.       br
d/debug print
.   RE
.PP
If value is set to 0, level information will not be added, and above messages
would like like this
.PP
.   RS
this is critical message
.       br
this is just an notice
.       br
debug print
.   RE
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input argument is different than 1 or 0
.       RE
.   RE
.RE
.PP
.BI "EL_FINFO (" int " finfo)"
.RS
If set to 1, adds information about log location to each message in format
[some_file.c:123]. Setting this to 0, will result in no file information at all
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input argument is different than 1 or 0
.       RE
.   RE
.RE
.PP
.BI "EL_FUNCINFO (" int " funcinfo)"
.RS
If set to 1, adds information about function from which message has been
printed in format [funcname()] or if
.   B EL_FINFO
is enabled [some_file.c:123:funcname()].
Settint this to 0 will result in no function information.
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input argument is different than 1 or 0
.       RE
.   RE
.RE
.PP
.B EL_CUSTOM_PUT (
.IB "int (*" el_custom_put ")(const char *s, size_t slen, void *user)" ,
.IB void\  *user
.B )
.RS
Sets function pointer for custom message print.
Function will receive complete messsage (after processsing) to print, just as it
would be printed to ie. stderr or another facility. Both binary and string data
can be received this way.
.   PP
.   I s
points to a data buffer, it can be null terminated string, or arbitrary binary
data - depending on which functions has been called.
.   PP
.   I slen
contains size of
.   I s
buffer.
If
.   I s
is null terminated string, then
.   I slen
contains length of string including null terminator character.
For binary data, it contains size of binary buffer.
.   PP
.   I user
pointer can be used to pass own logger object where data shall be sent.
For example it may contain pointer to
.   B el
struct, if you don't use global el struct.
.   PP
Function cannot fail. If NULL is passed, custom function won't be called.
It is still mandatory to enable custom printing with
.   BR el_option (3)\ -\  EL_OUT .
.RE
.PP
.BI "EL_FPATH (" const " " char " " * "path)"
.RS
Sets the
.I path
for the logs. Logs will be stored in this file. If file
rotation is enabled, a numer will be postfixed to each file. See
.   B EL_FROTATE_NUMBER
in this page for more details.
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input parameter is NULL
.       RE
.       PP
.       B ENAMETOOLONG
.       RS
File name is too long
.       RE
.       PP
Function can also fail and set
.       I errno
for any of the errors specified for the routing
.       BR fopen ()
.   RE
.PP
If function fails with
.B EINVAL
or
.BR ENAMETOOLONG ,
file is not opened and any calls that logs to file will
result in failure.
Any other error is in reality just a warning, meaning file could not have been
opened now, but embedlog will try to reopen in each time it logs to file.
.RE
.PP
.BI "EL_FROTATE_NUMBER (" long " number)"
.RS
If set to 0, file rotation will be disabled and logs will be printed into
specified file without size limit.
The only size limit is the one presented by the filesystem and architecture.
.   PP
If this value is bigger than 0, file rotation will be enabled. All files will
have suffixes added to name set in EL_FPATH. For example,
.   IR program.log.0 .
Files are enumareted from
.   I .0
to
.   IR .n ,
where
.   I n
is set rotate number.
File with suffix
.   I .0
is the oldest one, and the higher the number, the newer the file is.
If logger reaches maximum number of files, oldest one with suffix
.   I .0
will be deleted and suffixes of the files will be decremented by 1 (ie.
.   I log.1
will be renamed to
.   IR log.0 ,
.   I log.2
will be renamed to
.   I log.1
and so on).
.   PP
User can also pass 1 here, but if file reaches its size limit, it will be
deleted and printing will continue from the empty file
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Input parameter is less than 0
.       RE
.   RE
.RE
.PP
.BI "EL_FROTATE_SIZE (" long " size)"
.RS
This defines
.I size
at which files will be rotated.
If message being printed would overflow rotate size, current file will be closed
and new one will be created, and current message will be stored in that new
file.
It is guaranteed that file will not be bigger than value set in this option.
If log printed into file is bigger than configure rotate size, message will be
truncated, to prevent file bigger than configure rotate size.
It's very rare situation as it doesn't make a lot of sense to set rotate size to
such small value.
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Value is less than 1
.       RE
.   RE
.RE
.PP
.BI "EL_FSYNC_EVERY (" long " size)"
.RS
Simply writing data to file descriptor is not enough, metadata also has to be
synced or you are facing data loose on unexpected power loose.
Yes, data will be on block device, but entry to it in file system will not be
updated, thus system will think file did not change.
To prevent that one must sync data and metadata periodically.
Data will be synced every
.I size
of bytes written.
It basically translates to 'how much data am I ready to loose?'.
Set this too high and you may loose a significant ammout of data on power lose.
Set this too low and your performance goes out of the window.
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
Value is less than 0
.       RE
.   RE
.RE
.PP
.BI "EL_FSYNC_LEVEL (" enum " " el_level " level)"
.RS
If level of printed message is
.   I level
or less (that is higher priority), it will be synced to disk every single time
regardless of
.   B EL_FSYNC_EVERY
option.
Messages with level
.   B EL_FATAL
(that is also default value for level sync) are synced always regardless of any
options set.
Messages printed with functions that don't take log level, will be treated as
messages with
.   B EL_DBG
level.
If
.   I level
is set to
.   B EL_DBG
every message printed with any function will be immediately synced to drive
(careful with that, this will impact performance a great deal if you print a lot
of debug messages).
.   PP
.   B ERRORS
.   RS
.       B EINVAL
.       RS
specified
.       I level
is invalid (bigger than EL_DBG).
.       RE
.   RE
.RE
.PP
.BI "EL_TTY_DEV (" const\ char\ * "dev, " speed_t " speed)"
.RS
Tells
.I embedlog
to use
.I dev
serial device configured to
.IR speed .
Serial device will also be configured to transmit in 8 bits of data, without
parity and one stop bit (8N1).
Logger uses only transmit pin (TX) and will translate all
.B LF
into
.BR CR-LF .
If
.I speed
is configured to
.BR B0,
serial port settings will not be altered, library will simply open port and
will happily work on current serial settings.
.   PP
.   B ERRORS
.   RS
Function can return errors from
.   BR open ,
.   BR tcgetattr ,
.   B cfsetispeed
and
.   BR tcsetattr .
.   RE
.RE
.PP
.BI "EL_THREAD_SAFE (" int " safe)"
.RS
By default,
.   B embedlog
is not thread safe.
While it may be relatively safe to use it in multi-thread environment
when you are logging to
.   B stdio
or
.   BR stderr ,
this surely isn't the case for more complex outputs like printing to file.
Also, without
.   B EL_THREAD_SAFE
calling
.   BR el_pmemory (3)
may result in interlacing prints.
.   PP
So, when using embedlog in multi-threaded environment, it is advised to enable
.   B EL_THREAD_SAFE
by passing 1 as
.   I safe
argument.
.   B embedlog
will then
.   BR pthread_mutex_lock ()
whenever threads access
.   I el
object.
.   PP
.   B EL_THREAD_SAFE
call must be performed when no other threads are accessing
.   I el
object, since at this point it is not possible to lock the mutex.
Common usage is to enable thread safety at the beggining - right after
.   BR el_init (3),
and leave it to be destroyed by
.   BR el_cleanup (3).
.   PP
It is safe to call this option multiple time with same argument.
.B embedlog
will not allow for multiple initialization nor destruction of mutex.
When options is called for the second time with same argument (like 1),
nothing will happen and funciton will return 0.
.   PP
.   B ERRORS
.   RS
Function can return errors from
.       BR pthread_mutex_init (),
and
.       BR pthread_mutex_destroy ().
.       PP
.       B EINVAL
.       RS
.           I safe
is different than 1 or 0
.       RE
.   RE
.RE
.SH RETURN VALUE
.PP
On success 0 is returned. -1 is returned when any error occured.
.SH ERRORS
.TP
.B EINVAL
Passed
.I option
is invalid.
.TP
.B ENOSYS
Passed
.I option
is not supported on this system (support was not compiled)
.PP
Also check for error description of specific option that failed for more
informations
.SH SEE ALSO
.PP
.BR el_overview (7),
.BR el_cleanup (3),
.BR el_destroy (3),
.BR el_flush (3),
.BR el_init (3),
.BR el_new (3),
.BR el_ocleanup (3),
.BR el_oflush (3),
.BR el_oinit (3),
.BR el_operror (3),
.BR el_opmemory (3),
.BR el_opmemory_table (3),
.BR el_oprint (3),
.BR el_oputs (3),
.BR el_ovprint (3),
.BR el_perror (3),
.BR el_pmemory (3),
.BR el_pmemory_table (3),
.BR el_print (3),
.BR el_puts (3),
.BR el_vprint (3).