Commit graph

40 commits

Author SHA1 Message Date
Daniel Leung 3c2d0f37a3 logging: avoid identifier collisions
MISRA-C Rule 5.3 states that identifiers in inner scope should
not hide identifiers in outer scope.

The log output instances all named "log_output" in backends
collide with the "log_output" parameter of various functions.
This renames the variables in the backends to make them
more descriptive. Same goes for the buffers for some of
these instances as they are all named "buf", and "hostname"
being used in the network backend,  so they are renamed.

There are a few places where variables are overriden within
an inner scope (e.g. inside loop and if block) so they are
also renamed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-07-25 21:26:15 -04:00
David D cf582284f7 logging: always add ids_print() to prefix even when using net backend
When using net log backend,
    adding severity and function name to log message.
    The log module name is a useful information when looking
    at log entries. This way remote log entries will
    contain the log module name.

Signed-off-by: David D <a8961713@gmail.com>
2020-07-21 15:09:13 +02:00
David D e023928e57 logging: Fixing timestamp calculation when using NEWLIB
corrected seconds value for gmtime() when using LOG_BACKEND_NET and
    NEWLIB_LIBC

Signed-off-by: David D <a8961713@gmail.com>
2020-07-21 10:29:04 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Xavier Chapron e5aaf21a73 subsys: Replace printf by printk when applicable
Signed-off-by: Xavier Chapron <xavier.chapron@stimio.fr>
2020-05-09 21:25:33 +02:00
Krzysztof Chruscinski 117fab3004 logging: log_output: Improve immediate mode handling
When in immediate mode ensure that buffering is not used in log output.
Every byte is pushed to the transport.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-12-18 13:08:46 -08:00
Wentong Wu dd9480913e logging: add syst format output
Add syst format output support for existing logging system.

Fixes: #19841.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-10-29 10:18:51 +01:00
Jukka Rissanen dc7b307a47 logging: Print hexdumps with 16 bytes in one line
The hexdump was earlier printed using 8 bytes in one line like this

[00:00:00.131,143] <wrn> sample_instance.inst2: Example of hexdump:
01 02 03 04 05 06 07 08 |........
09 0a 0b 0c 0d 0e 0f 10 |........
11 12 13 14 15 16 17 18 |........
19 1a 1b 1c 1d 1e 1f 20 |.......
21 22                   |!"

This is not utilizing the width of the output best way possible.

Better utilization of the output is to print 16 bytes in one line
like this:

[00:00:00.131,136] <wrn> sample_instance.inst2: Example of hexdump:
01 02 03 04 05 06 07 08  09 0a 0b 0c 0d 0e 0f 10 |........ ........
11 12 13 14 15 16 17 18  19 1a 1b 1c 1d 1e 1f 20 |........ .......
21 22                                            |!"

In order to make it easier to find / calculate the bytes in the
output, print the output bytes in 8 byte groups.

This has the benefit that it is easier to map the Zephyr hex output
to Wireshark output which prints the bytes like this.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-10-11 17:53:50 +02:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Krzysztof Chruscinski 0e72962a77 logging: replace assert calls with __ASSERT_NO_MSG
File was using not recommended assert call.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-18 11:28:50 -05:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Krzysztof Chruscinski 987586d914 logging: Use vprintk for string formatting by default
Previously, _prf function was used when present and _vprintk
was used otherwise. _prf supports reacher formatting but at
cost of 3k flash and >250 bytes on stack. Stack usage then
depended on which function was used and that was causing
troubles when trimming stack sizes.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-05 08:24:50 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Michael Scott d646eff3d3 logging: introduce LOG_DISABLE_FANCY_OUTPUT_FORMATTING to save flash
The new Logger subsys uses a very robust formatter function in minimal
libc: _prf().  This adds up to ~3K flash.  For resource constrained
devices running samples that don't use the extra formatting options,
allow them to select LOG_DISABLE_FANCY_OUTPUT_FORMATTING to revert
back to vprintk.

MCUBOOT is one such sample that has a very limited amount of output
and benefits from the flash savings due to small bootloader partition
sizes.

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-04 08:04:38 -05:00
Krzysztof Chruscinski 08e5103105 logging: Extend log_output to support raw data
Added functions for processing log string and hexdump. Details
are passed as function parameters and not as log_msg. Those
functions can be used when logger works in  synchronous mode
and log messages are not created.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Krzysztof Chruscinski 1d9e5ee108 logging: Refactoring 'in place' mode to reduce memory footprint
Changed 'in place' mode to bypass logger system and directly
call active backends. With this approach memory footprint of
the logger can be significantly reduced in terms of RAM and ROM.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-01-29 17:24:37 +01:00
Flavio Ceolin f342019986 log: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-01-07 08:52:07 -05:00
Flavio Ceolin 1036edcfbb log: Fix switch statement
MISRA-C has several rules about switch statements like each clause
end with an unconditional break. This commit fix these problems to
be in accordance with the standard.

MISRA-C rules 16.1, 16.3 and 16.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-21 21:06:18 +01:00
Krzysztof Chruscinski a7568e4a6a logging: Handle dropped messages in log_output
Extended log_output interface to handle dropped
messages. Log_output is printing a message containing
number of dropped messages.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-18 13:42:41 +01:00
Krzysztof Chruscinski 0899a6c0b7 logging: severity-wise filtering of function name prefix presence
Extended logger configuration to allow function name prefix for
messages with certain severity levels. By default only debug
messages are prefixed with function name.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-12-13 14:21:25 +01:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Jukka Rissanen 44a9bb6abe logging: Add network backend
Allow logging subsystem to send the logging messages to outside
system. This backend implements RFC 5424 (syslog protocol) and
RFC 5426 (syslog over UDP).

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-12-04 15:55:53 -05:00
Krzysztof Chruscinski 2d6a226b2e logging: Fix lost printk output when no newline
Log_output module was always postfixing printk strings
with '\r'. If printk message did not ended with '\n'
it lead to last printk message being overwritten.

Fixed by adding '\r' only when string was ended by '\n'.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-22 19:18:41 -05:00
Flavio Ceolin 3ced176088 subsys: logging: Fix switch statement
According with MISRA-C and unconditional break statement must
terminate every switch-clause.

MISRA-C rule 16.1 and 16.3

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-06 16:20:15 -05:00
Krzysztof Chruscinski 62d011549a logging: Support for up to 15 arguments in log message
Extended support in the log_core and log_output to 15 arguments
which is the hard limitation of log message format.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-11-02 12:22:01 -04:00
Krzysztof Chruscinski 5d28fcd689 logging: Add optional function name prefix
Extended logger to support optional log message prepending with
function name.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-24 11:14:26 +01:00
Krzysztof Chruscinski c696e68bb9 logging: Added support for 10 arguments in log message
Extended supported number of arguments in log message. Support for
messages consisting of more than 2 chunks had to be added. So far
messages could consist of one chunk (up to 3 args) or two chunks
(2 args in first chunk and 7 in second chunk). Once 2+ chunks
support is added number of arguments is techinically limited to
15 (4 bit field). log_core and log_output extended to suppor 10
arguments.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-10-24 11:14:26 +01:00
Carles Cufi 322647129f subsys: logging: Add CR/LF handling flags
Add 2 new flags to control the output of newlines by the logger output
module. By default the logger adds both CR and LF, and with these 2 new
flags it is now possible to request LF only or no newlines at all.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-10-18 17:53:11 -04:00
Krzysztof Chruscinski 2cc6d0c9c2 logging: Add option to suppress timestamp printing in log_output
Added flag in log_output module to add timestamp when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Krzysztof Chruscinski 07da32aae5 logging: Add option to suppress level printing in log_output
Added flag in log_output module to add severity level when message is
formatted to a string. Updated existing backends.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-26 15:01:38 +02:00
Andrei Emeltchenko e65ee6870e logger: Add native backend for native_posix
Add backend to be used in native_posix arch.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2018-09-18 14:56:10 +02:00
Krzysztof Chruscinski 1fbea945f4 logging: Refactor log_output module
Module refactored: splitted data into read-only part and control block,
adding macro for creating log_output instance

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-09-14 15:05:50 +02:00
Krzysztof Chruscinski 3c63d05dfc logging: Add metadata to hexdump
Extended hexdump API with a raw string attached to the data.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-08-14 07:14:34 -07:00
Johan Hedberg 83db9ad753 logging: Make prefixes the same length
Make the severity level prefixes the same length. This helps both
readability of mixed level logs, and it's also consistent with how the
levels are named in the public API macros.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-07-19 16:23:19 -04:00
Krzysztof Chruscinski d731e539ce logging: Handle 0 Hz frequency in log_output
It is possible that user provides 0 hz frquency to the log_output
(if CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=0). In that case timestamp
must not be formatted to avoid division by 0.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-11 10:56:07 -04:00
Krzysztof Chruscinski e854dd0069 logging: log_output: Data lost because of uninitialized variable
Uninitialized variable error could lead to a situation where
printk calls processed by the logger were dropped.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2018-07-09 12:09:43 -04:00
Jukka Rissanen f10cbe5ee9 logging: Print 7, 8 or 9 parameter macros properly
The log prints for 7, 8 and 9 parameters were not properly printed.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2018-07-09 11:16:49 -04:00
Krzysztof Chruściński bbeef4155c logging: subsystem major redesign
Adding new implementation of logging subsystem. New features
includes: support for multiple backends, improving performance
by deferring log processing to the known context, adding
timestamps and logs filtering options (compile time, runtime,
module level, instance level). Console backend added as the
example backend.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2018-06-29 10:16:45 +02:00