log.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Logging support
  4. *
  5. * Copyright (c) 2017 Google, Inc
  6. * Written by Simon Glass <sjg@chromium.org>
  7. */
  8. #ifndef __LOG_H
  9. #define __LOG_H
  10. #include <stdio.h>
  11. #include <linker_lists.h>
  12. #include <dm/uclass-id.h>
  13. #include <linux/bitops.h>
  14. #include <linux/list.h>
  15. struct cmd_tbl;
  16. /**
  17. * enum log_level_t - Log levels supported, ranging from most to least important
  18. */
  19. enum log_level_t {
  20. /** @LOGL_EMERG: U-Boot is unstable */
  21. LOGL_EMERG = 0,
  22. /** @LOGL_ALERT: Action must be taken immediately */
  23. LOGL_ALERT,
  24. /** @LOGL_CRIT: Critical conditions */
  25. LOGL_CRIT,
  26. /** @LOGL_ERR: Error that prevents something from working */
  27. LOGL_ERR,
  28. /** @LOGL_WARNING: Warning may prevent optimal operation */
  29. LOGL_WARNING,
  30. /** @LOGL_NOTICE: Normal but significant condition, printf() */
  31. LOGL_NOTICE,
  32. /** @LOGL_INFO: General information message */
  33. LOGL_INFO,
  34. /** @LOGL_DEBUG: Basic debug-level message */
  35. LOGL_DEBUG,
  36. /** @LOGL_DEBUG_CONTENT: Debug message showing full message content */
  37. LOGL_DEBUG_CONTENT,
  38. /** @LOGL_DEBUG_IO: Debug message showing hardware I/O access */
  39. LOGL_DEBUG_IO,
  40. /** @LOGL_COUNT: Total number of valid log levels */
  41. LOGL_COUNT,
  42. /** @LOGL_NONE: Used to indicate that there is no valid log level */
  43. LOGL_NONE,
  44. /** @LOGL_LEVEL_MASK: Mask for valid log levels */
  45. LOGL_LEVEL_MASK = 0xf,
  46. /** @LOGL_FORCE_DEBUG: Mask to force output due to LOG_DEBUG */
  47. LOGL_FORCE_DEBUG = 0x10,
  48. /** @LOGL_FIRST: The first, most-important log level */
  49. LOGL_FIRST = LOGL_EMERG,
  50. /** @LOGL_MAX: The last, least-important log level */
  51. LOGL_MAX = LOGL_DEBUG_IO,
  52. /** @LOGL_CONT: Use same log level as in previous call */
  53. LOGL_CONT = -1,
  54. };
  55. /**
  56. * enum log_category_t - Log categories supported.
  57. *
  58. * Log categories between %LOGC_FIRST and %LOGC_NONE correspond to uclasses
  59. * (i.e. &enum uclass_id), but there are also some more generic categories.
  60. *
  61. * Remember to update log_cat_name[] after adding a new category.
  62. */
  63. enum log_category_t {
  64. /** @LOGC_FIRST: First log category */
  65. LOGC_FIRST = 0, /* First part mirrors UCLASS_... */
  66. /** @LOGC_NONE: Default log category */
  67. LOGC_NONE = UCLASS_COUNT, /* First number is after all uclasses */
  68. /** @LOGC_ARCH: Related to arch-specific code */
  69. LOGC_ARCH,
  70. /** @LOGC_BOARD: Related to board-specific code */
  71. LOGC_BOARD,
  72. /** @LOGC_CORE: Related to core features (non-driver-model) */
  73. LOGC_CORE,
  74. /** @LOGC_DM: Core driver-model */
  75. LOGC_DM,
  76. /** @LOGC_DT: Device-tree */
  77. LOGC_DT,
  78. /** @LOGC_EFI: EFI implementation */
  79. LOGC_EFI,
  80. /** @LOGC_ALLOC: Memory allocation */
  81. LOGC_ALLOC,
  82. /** @LOGC_SANDBOX: Related to the sandbox board */
  83. LOGC_SANDBOX,
  84. /** @LOGC_BLOBLIST: Bloblist */
  85. LOGC_BLOBLIST,
  86. /** @LOGC_DEVRES: Device resources (``devres_...`` functions) */
  87. LOGC_DEVRES,
  88. /** @LOGC_ACPI: Advanced Configuration and Power Interface (ACPI) */
  89. LOGC_ACPI,
  90. /** @LOGC_BOOT: Related to boot process / boot image processing */
  91. LOGC_BOOT,
  92. /** @LOGC_COUNT: Number of log categories */
  93. LOGC_COUNT,
  94. /** @LOGC_END: Sentinel value for lists of log categories */
  95. LOGC_END,
  96. /** @LOGC_CONT: Use same category as in previous call */
  97. LOGC_CONT = -1,
  98. };
  99. /* Helper to cast a uclass ID to a log category */
  100. static inline int log_uc_cat(enum uclass_id id)
  101. {
  102. return (enum log_category_t)id;
  103. }
  104. /**
  105. * _log() - Internal function to emit a new log record
  106. *
  107. * @cat: Category of log record (indicating which subsystem generated it)
  108. * @level: Level of log record (indicating its severity)
  109. * @file: File name of file where log record was generated
  110. * @line: Line number in file where log record was generated
  111. * @func: Function where log record was generated
  112. * @fmt: printf() format string for log record
  113. * @...: Optional parameters, according to the format string @fmt
  114. * Return: 0 if log record was emitted, -ve on error
  115. */
  116. int _log(enum log_category_t cat, enum log_level_t level, const char *file,
  117. int line, const char *func, const char *fmt, ...)
  118. __attribute__ ((format (__printf__, 6, 7)));
  119. static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
  120. const char *file, int line, const char *func,
  121. const char *fmt, ...)
  122. __attribute__ ((format (__printf__, 6, 7)));
  123. static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
  124. const char *file, int line, const char *func,
  125. const char *fmt, ...)
  126. {
  127. return 0;
  128. }
  129. /* Define this at the top of a file to add a prefix to debug messages */
  130. #ifndef pr_fmt
  131. #define pr_fmt(fmt) fmt
  132. #endif
  133. /* Use a default category if this file does not supply one */
  134. #ifndef LOG_CATEGORY
  135. #define LOG_CATEGORY LOGC_NONE
  136. #endif
  137. /*
  138. * This header may be including when CONFIG_LOG is disabled, in which case
  139. * CONFIG_LOG_MAX_LEVEL is not defined. Add a check for this.
  140. */
  141. #if CONFIG_IS_ENABLED(LOG)
  142. #define _LOG_MAX_LEVEL CONFIG_VAL(LOG_MAX_LEVEL)
  143. #define log_err(_fmt...) log(LOG_CATEGORY, LOGL_ERR, ##_fmt)
  144. #define log_warning(_fmt...) log(LOG_CATEGORY, LOGL_WARNING, ##_fmt)
  145. #define log_notice(_fmt...) log(LOG_CATEGORY, LOGL_NOTICE, ##_fmt)
  146. #define log_info(_fmt...) log(LOG_CATEGORY, LOGL_INFO, ##_fmt)
  147. #define log_debug(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG, ##_fmt)
  148. #define log_content(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG_CONTENT, ##_fmt)
  149. #define log_io(_fmt...) log(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt)
  150. #else
  151. #define _LOG_MAX_LEVEL LOGL_INFO
  152. #define log_err(_fmt, ...) printf(_fmt, ##__VA_ARGS__)
  153. #define log_warning(_fmt, ...) printf(_fmt, ##__VA_ARGS__)
  154. #define log_notice(_fmt, ...) printf(_fmt, ##__VA_ARGS__)
  155. #define log_info(_fmt, ...) printf(_fmt, ##__VA_ARGS__)
  156. #define log_debug(_fmt, ...) debug(_fmt, ##__VA_ARGS__)
  157. #define log_content(_fmt...) log_nop(LOG_CATEGORY, \
  158. LOGL_DEBUG_CONTENT, ##_fmt)
  159. #define log_io(_fmt...) log_nop(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt)
  160. #endif
  161. #if CONFIG_IS_ENABLED(LOG)
  162. #ifdef LOG_DEBUG
  163. #define _LOG_DEBUG LOGL_FORCE_DEBUG
  164. #else
  165. #define _LOG_DEBUG 0
  166. #endif
  167. /* Emit a log record if the level is less that the maximum */
  168. #define log(_cat, _level, _fmt, _args...) ({ \
  169. int _l = _level; \
  170. if (CONFIG_IS_ENABLED(LOG) && \
  171. (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL)) \
  172. _log((enum log_category_t)(_cat), \
  173. (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \
  174. __LINE__, __func__, \
  175. pr_fmt(_fmt), ##_args); \
  176. })
  177. #else
  178. #define log(_cat, _level, _fmt, _args...)
  179. #endif
  180. #define log_nop(_cat, _level, _fmt, _args...) ({ \
  181. int _l = _level; \
  182. _log_nop((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \
  183. __func__, pr_fmt(_fmt), ##_args); \
  184. })
  185. #ifdef DEBUG
  186. #define _DEBUG 1
  187. #else
  188. #define _DEBUG 0
  189. #endif
  190. #ifdef CONFIG_SPL_BUILD
  191. #define _SPL_BUILD 1
  192. #else
  193. #define _SPL_BUILD 0
  194. #endif
  195. #if !_DEBUG && CONFIG_IS_ENABLED(LOG)
  196. #define debug_cond(cond, fmt, args...) \
  197. do { \
  198. if (1) \
  199. log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \
  200. } while (0)
  201. #else /* _DEBUG */
  202. /*
  203. * Output a debug text when condition "cond" is met. The "cond" should be
  204. * computed by a preprocessor in the best case, allowing for the best
  205. * optimization.
  206. */
  207. #define debug_cond(cond, fmt, args...) \
  208. do { \
  209. if (cond) \
  210. printf(pr_fmt(fmt), ##args); \
  211. } while (0)
  212. #endif /* _DEBUG */
  213. /* Show a message if DEBUG is defined in a file */
  214. #define debug(fmt, args...) \
  215. debug_cond(_DEBUG, fmt, ##args)
  216. /* Show a message if not in SPL */
  217. #define warn_non_spl(fmt, args...) \
  218. debug_cond(!_SPL_BUILD, fmt, ##args)
  219. /*
  220. * An assertion is run-time check done in debug mode only. If DEBUG is not
  221. * defined then it is skipped. If DEBUG is defined and the assertion fails,
  222. * then it calls panic*( which may or may not reset/halt U-Boot (see
  223. * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
  224. * before release, and after release it is hoped that they don't matter. But
  225. * in any case these failing assertions cannot be fixed with a reset (which
  226. * may just do the same assertion again).
  227. */
  228. void __assert_fail(const char *assertion, const char *file, unsigned int line,
  229. const char *function);
  230. /**
  231. * assert() - assert expression is true
  232. *
  233. * If the expression x evaluates to false and _DEBUG evaluates to true, a panic
  234. * message is written and the system stalls. The value of _DEBUG is set to true
  235. * if DEBUG is defined before including common.h.
  236. *
  237. * The expression x is always executed irrespective of the value of _DEBUG.
  238. *
  239. * @x: expression to test
  240. */
  241. #define assert(x) \
  242. ({ if (!(x) && _DEBUG) \
  243. __assert_fail(#x, __FILE__, __LINE__, __func__); })
  244. /*
  245. * This one actually gets compiled in even without DEBUG. It doesn't include the
  246. * full pathname as it may be huge. Only use this when the user should be
  247. * warning, similar to BUG_ON() in linux.
  248. *
  249. * Return: true if assertion succeeded (condition is true), else false
  250. */
  251. #define assert_noisy(x) \
  252. ({ bool _val = (x); \
  253. if (!_val) \
  254. __assert_fail(#x, "?", __LINE__, __func__); \
  255. _val; \
  256. })
  257. #if CONFIG_IS_ENABLED(LOG) && defined(CONFIG_LOG_ERROR_RETURN)
  258. /*
  259. * Log an error return value, possibly with a message. Usage:
  260. *
  261. * return log_ret(fred_call());
  262. *
  263. * or:
  264. *
  265. * return log_msg_ret("fred failed", fred_call());
  266. */
  267. #define log_ret(_ret) ({ \
  268. int __ret = (_ret); \
  269. if (__ret < 0) \
  270. log(LOG_CATEGORY, LOGL_ERR, "returning err=%d\n", __ret); \
  271. __ret; \
  272. })
  273. #define log_msg_ret(_msg, _ret) ({ \
  274. int __ret = (_ret); \
  275. if (__ret < 0) \
  276. log(LOG_CATEGORY, LOGL_ERR, "%s: returning err=%d\n", _msg, \
  277. __ret); \
  278. __ret; \
  279. })
  280. #else
  281. /* Non-logging versions of the above which just return the error code */
  282. #define log_ret(_ret) (_ret)
  283. #define log_msg_ret(_msg, _ret) ((void)(_msg), _ret)
  284. #endif
  285. /**
  286. * struct log_rec - a single log record
  287. *
  288. * Holds information about a single record in the log
  289. *
  290. * Members marked as 'not allocated' are stored as pointers and the caller is
  291. * responsible for making sure that the data pointed to is not overwritten.
  292. * Members marked as 'allocated' are allocated (e.g. via strdup()) by the log
  293. * system.
  294. *
  295. * TODO(sjg@chromium.org): Compress this struct down a bit to reduce space, e.g.
  296. * a single u32 for cat, level, line and force_debug
  297. *
  298. * @cat: Category, representing a uclass or part of U-Boot
  299. * @level: Severity level, less severe is higher
  300. * @force_debug: Force output of debug
  301. * @file: Name of file where the log record was generated (not allocated)
  302. * @line: Line number where the log record was generated
  303. * @func: Function where the log record was generated (not allocated)
  304. * @msg: Log message (allocated)
  305. */
  306. struct log_rec {
  307. enum log_category_t cat;
  308. enum log_level_t level;
  309. bool force_debug;
  310. const char *file;
  311. int line;
  312. const char *func;
  313. const char *msg;
  314. };
  315. struct log_device;
  316. enum log_device_flags {
  317. LOGDF_ENABLE = BIT(0), /* Device is enabled */
  318. };
  319. /**
  320. * struct log_driver - a driver which accepts and processes log records
  321. *
  322. * @name: Name of driver
  323. * @emit: Method to call to emit a log record via this device
  324. * @flags: Initial value for flags (use LOGDF_ENABLE to enable on start-up)
  325. */
  326. struct log_driver {
  327. const char *name;
  328. /**
  329. * @emit: emit a log record
  330. *
  331. * Called by the log system to pass a log record to a particular driver
  332. * for processing. The filter is checked before calling this function.
  333. */
  334. int (*emit)(struct log_device *ldev, struct log_rec *rec);
  335. unsigned short flags;
  336. };
  337. /**
  338. * struct log_device - an instance of a log driver
  339. *
  340. * Since drivers are set up at build-time we need to have a separate device for
  341. * the run-time aspects of drivers (currently just a list of filters to apply
  342. * to records send to this device).
  343. *
  344. * @next_filter_num: Sequence number of next filter filter added (0=no filters
  345. * yet). This increments with each new filter on the device, but never
  346. * decrements
  347. * @flags: Flags for this filter (enum log_device_flags)
  348. * @drv: Pointer to driver for this device
  349. * @filter_head: List of filters for this device
  350. * @sibling_node: Next device in the list of all devices
  351. */
  352. struct log_device {
  353. unsigned short next_filter_num;
  354. unsigned short flags;
  355. struct log_driver *drv;
  356. struct list_head filter_head;
  357. struct list_head sibling_node;
  358. };
  359. enum {
  360. LOGF_MAX_CATEGORIES = 5, /* maximum categories per filter */
  361. };
  362. /**
  363. * enum log_filter_flags - Flags which modify a filter
  364. */
  365. enum log_filter_flags {
  366. /** @LOGFF_HAS_CAT: Filter has a category list */
  367. LOGFF_HAS_CAT = 1 << 0,
  368. /** @LOGFF_DENY: Filter denies matching messages */
  369. LOGFF_DENY = 1 << 1,
  370. /** @LOGFF_LEVEL_MIN: Filter's level is a minimum, not a maximum */
  371. LOGFF_LEVEL_MIN = 1 << 2,
  372. };
  373. /**
  374. * struct log_filter - criteria to filter out log messages
  375. *
  376. * If a message matches all criteria, then it is allowed. If LOGFF_DENY is set,
  377. * then it is denied instead.
  378. *
  379. * @filter_num: Sequence number of this filter. This is returned when adding a
  380. * new filter, and must be provided when removing a previously added
  381. * filter.
  382. * @flags: Flags for this filter (``LOGFF_...``)
  383. * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty
  384. * then all categories are permitted. Up to %LOGF_MAX_CATEGORIES entries
  385. * can be provided
  386. * @level: Maximum (or minimum, if %LOGFF_MIN_LEVEL) log level to allow
  387. * @file_list: List of files to allow, separated by comma. If NULL then all
  388. * files are permitted
  389. * @sibling_node: Next filter in the list of filters for this log device
  390. */
  391. struct log_filter {
  392. int filter_num;
  393. int flags;
  394. enum log_category_t cat_list[LOGF_MAX_CATEGORIES];
  395. enum log_level_t level;
  396. const char *file_list;
  397. struct list_head sibling_node;
  398. };
  399. #define LOG_DRIVER(_name) \
  400. ll_entry_declare(struct log_driver, _name, log_driver)
  401. /* Get a pointer to a given driver */
  402. #define LOG_GET_DRIVER(__name) \
  403. ll_entry_get(struct log_driver, __name, log_driver)
  404. /**
  405. * log_get_cat_name() - Get the name of a category
  406. *
  407. * @cat: Category to look up
  408. * Return: category name (which may be a uclass driver name) if found, or
  409. * "<invalid>" if invalid, or "<missing>" if not found. All error
  410. * responses begin with '<'.
  411. */
  412. const char *log_get_cat_name(enum log_category_t cat);
  413. /**
  414. * log_get_cat_by_name() - Look up a category by name
  415. *
  416. * @name: Name to look up
  417. * Return: Category, or %LOGC_NONE if not found
  418. */
  419. enum log_category_t log_get_cat_by_name(const char *name);
  420. /**
  421. * log_get_level_name() - Get the name of a log level
  422. *
  423. * @level: Log level to look up
  424. * Return: Log level name (in ALL CAPS)
  425. */
  426. const char *log_get_level_name(enum log_level_t level);
  427. /**
  428. * log_get_level_by_name() - Look up a log level by name
  429. *
  430. * @name: Name to look up
  431. * Return: Log level, or %LOGL_NONE if not found
  432. */
  433. enum log_level_t log_get_level_by_name(const char *name);
  434. /**
  435. * log_device_find_by_name() - Look up a log device by its driver's name
  436. *
  437. * @drv_name: Name of the driver
  438. * Return: the log device, or %NULL if not found
  439. */
  440. struct log_device *log_device_find_by_name(const char *drv_name);
  441. /**
  442. * log_has_cat() - check if a log category exists within a list
  443. *
  444. * @cat_list: List of categories to check, at most %LOGF_MAX_CATEGORIES entries
  445. * long, terminated by %LC_END if fewer
  446. * @cat: Category to search for
  447. *
  448. * Return: ``true`` if @cat is in @cat_list, else ``false``
  449. */
  450. bool log_has_cat(enum log_category_t cat_list[], enum log_category_t cat);
  451. /**
  452. * log_has_file() - check if a file is with a list
  453. *
  454. * @file_list: List of files to check, separated by comma
  455. * @file: File to check for. This string is matched against the end of each
  456. * file in the list, i.e. ignoring any preceding path. The list is
  457. * intended to consist of relative pathnames, e.g. common/main.c,cmd/log.c
  458. *
  459. * Return: ``true`` if @file is in @file_list, else ``false``
  460. */
  461. bool log_has_file(const char *file_list, const char *file);
  462. /* Log format flags (bit numbers) for gd->log_fmt. See log_fmt_chars */
  463. enum log_fmt {
  464. LOGF_CAT = 0,
  465. LOGF_LEVEL,
  466. LOGF_FILE,
  467. LOGF_LINE,
  468. LOGF_FUNC,
  469. LOGF_MSG,
  470. LOGF_COUNT,
  471. LOGF_ALL = 0x3f,
  472. };
  473. /* Handle the 'log test' command */
  474. int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
  475. /**
  476. * log_add_filter_flags() - Add a new filter to a log device, specifying flags
  477. *
  478. * @drv_name: Driver name to add the filter to (since each driver only has a
  479. * single device)
  480. * @flags: Flags for this filter (``LOGFF_...``)
  481. * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty
  482. * then all categories are permitted. Up to %LOGF_MAX_CATEGORIES entries
  483. * can be provided
  484. * @level: Maximum (or minimum, if %LOGFF_LEVEL_MIN) log level to allow
  485. * @file_list: List of files to allow, separated by comma. If NULL then all
  486. * files are permitted
  487. * Return:
  488. * the sequence number of the new filter (>=0) if the filter was added, or a
  489. * -ve value on error
  490. */
  491. int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[],
  492. enum log_level_t level, const char *file_list,
  493. int flags);
  494. /**
  495. * log_add_filter() - Add a new filter to a log device
  496. *
  497. * @drv_name: Driver name to add the filter to (since each driver only has a
  498. * single device)
  499. * @cat_list: List of categories to allow (terminated by %LOGC_END). If empty
  500. * then all categories are permitted. Up to %LOGF_MAX_CATEGORIES entries
  501. * can be provided
  502. * @max_level: Maximum log level to allow
  503. * @file_list: List of files to allow, separated by comma. If %NULL then all
  504. * files are permitted
  505. * Return:
  506. * the sequence number of the new filter (>=0) if the filter was added, or a
  507. * -ve value on error
  508. */
  509. static inline int log_add_filter(const char *drv_name,
  510. enum log_category_t cat_list[],
  511. enum log_level_t max_level,
  512. const char *file_list)
  513. {
  514. return log_add_filter_flags(drv_name, cat_list, max_level, file_list,
  515. 0);
  516. }
  517. /**
  518. * log_remove_filter() - Remove a filter from a log device
  519. *
  520. * @drv_name: Driver name to remove the filter from (since each driver only has
  521. * a single device)
  522. * @filter_num: Filter number to remove (as returned by log_add_filter())
  523. * Return:
  524. * 0 if the filter was removed, -%ENOENT if either the driver or the filter
  525. * number was not found
  526. */
  527. int log_remove_filter(const char *drv_name, int filter_num);
  528. /**
  529. * log_device_set_enable() - Enable or disable a log device
  530. *
  531. * Devices are referenced by their driver, so use LOG_GET_DRIVER(name) to pass
  532. * the driver to this function. For example if the driver is declared with
  533. * LOG_DRIVER(wibble) then pass LOG_GET_DRIVER(wibble) here.
  534. *
  535. * @drv: Driver of device to enable
  536. * @enable: true to enable, false to disable
  537. * @return 0 if OK, -ENOENT if the driver was not found
  538. */
  539. int log_device_set_enable(struct log_driver *drv, bool enable);
  540. #if CONFIG_IS_ENABLED(LOG)
  541. /**
  542. * log_init() - Set up the log system ready for use
  543. *
  544. * Return: 0 if OK, -%ENOMEM if out of memory
  545. */
  546. int log_init(void);
  547. #else
  548. static inline int log_init(void)
  549. {
  550. return 0;
  551. }
  552. #endif
  553. /**
  554. * log_get_default_format() - get default log format
  555. *
  556. * The default log format is configurable via
  557. * %CONFIG_LOGF_FILE, %CONFIG_LOGF_LINE, and %CONFIG_LOGF_FUNC.
  558. *
  559. * Return: default log format
  560. */
  561. static inline int log_get_default_format(void)
  562. {
  563. return BIT(LOGF_MSG) |
  564. (IS_ENABLED(CONFIG_LOGF_FILE) ? BIT(LOGF_FILE) : 0) |
  565. (IS_ENABLED(CONFIG_LOGF_LINE) ? BIT(LOGF_LINE) : 0) |
  566. (IS_ENABLED(CONFIG_LOGF_FUNC) ? BIT(LOGF_FUNC) : 0);
  567. }
  568. #endif