Skip to content

Commit c4ed789

Browse files
committed
feat log: added modules examples
Signed-off-by: Zhenlin Wang <sanpeqf@gmail.com>
1 parent 56b1601 commit c4ed789

File tree

3 files changed

+33
-51
lines changed

3 files changed

+33
-51
lines changed

examples/log/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ add_executable(log-simple simple.c)
77
target_link_libraries(log-simple bfdev)
88
add_test(log-simple log-simple)
99

10-
add_executable(log-date date.c)
11-
target_link_libraries(log-date bfdev)
12-
add_test(log-date log-date)
10+
add_executable(log-modules modules.c)
11+
target_link_libraries(log-modules bfdev)
12+
add_test(log-modules log-modules)
1313

1414
if(${CMAKE_PROJECT_NAME} STREQUAL "bfdev")
1515
install(FILES
1616
simple.c
17-
date.c
17+
modules.c
1818
DESTINATION
1919
${CMAKE_INSTALL_DOCDIR}/examples/log
2020
)
2121

2222
install(TARGETS
2323
log-simple
24-
log-date
24+
log-modules
2525
DESTINATION
2626
${CMAKE_INSTALL_DOCDIR}/bin
2727
)

examples/log/date.c

Lines changed: 0 additions & 46 deletions
This file was deleted.

examples/log/modules.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright(c) 2023 Zhenlin Wang <sanpeqf@gmail.com>
4+
*/
5+
6+
#define MODULE_NAME "log-modules"
7+
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt
8+
9+
#include <bfdev/log.h>
10+
#include <bfdev/modules/log.h>
11+
#include <unistd.h>
12+
13+
int
14+
main(int argc, const char *argv[])
15+
{
16+
unsigned int count;
17+
18+
bfdev_log_localtime_enable(&bfdev_log_default);
19+
bfdev_log_hostname_enable(&bfdev_log_default);
20+
bfdev_log_pid_enable(&bfdev_log_default);
21+
22+
for (count = 0; count < 3; ++count) {
23+
bfdev_log_info("Hello World!\n");
24+
sleep(1);
25+
}
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)