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