Skip to content

Commit 3f34fea

Browse files
jukkargalak
authored andcommitted
log: net: Fix the immediate logging mode in network backend
If CONFIG_LOG_IMMEDIATE is enabled, then we need to handle the output strings using a different output function. The issue was noticed with native_posix board where no syslog output strings were sent to network. Fixes #14661 Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 111dab4 commit 3f34fea

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

subsys/logging/log_backend_net.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ static void send_output(const struct log_backend *const backend,
177177
return;
178178
}
179179

180-
if (!net_init_done) {
180+
if (!net_init_done && do_net_init() == 0) {
181181
net_init_done = true;
182-
if (do_net_init() < 0) {
183-
net_init_done = false;
184-
}
185182
}
186183

187184
log_msg_get(msg);
@@ -215,10 +212,34 @@ static void panic(struct log_backend const *const backend)
215212
panic_mode = true;
216213
}
217214

215+
static void sync_string(const struct log_backend *const backend,
216+
struct log_msg_ids src_level, u32_t timestamp,
217+
const char *fmt, va_list ap)
218+
{
219+
u32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_FORMAT_SYSLOG |
220+
LOG_OUTPUT_FLAG_TIMESTAMP;
221+
u32_t key;
222+
223+
if (!net_init_done && do_net_init() == 0) {
224+
net_init_done = true;
225+
}
226+
227+
key = irq_lock();
228+
log_output_string(&log_output, src_level, timestamp, fmt, ap, flags);
229+
irq_unlock(key);
230+
}
231+
218232
const struct log_backend_api log_backend_net_api = {
219-
.put = send_output,
220233
.panic = panic,
221234
.init = init_net,
235+
.put = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : send_output,
236+
.put_sync_string = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ?
237+
sync_string : NULL,
238+
/* Currently we do not send hexdumps over network to remote server
239+
* in CONFIG_LOG_IMMEDIATE_MODE. This is just to save resources,
240+
* this can be revisited if needed.
241+
*/
242+
.put_sync_hexdump = NULL,
222243
};
223244

224245
/* Note that the backend can be activated only after we have networking

0 commit comments

Comments
 (0)