MOS Source Code
Loading...
Searching...
No Matches
syslog.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "mos/syslog/syslog.h"
4
7#include "proto/syslog.pb.h"
8
9#include <mos/compiler.h>
10#include <mos/mos_global.h>
11#include <mos_stdio.h>
12#include <pb_encode.h>
13
15
16long do_syslog(loglevel_t level, thread_t *thread, const char *file, const char *func, int line, debug_info_entry *feat, const char *fmt, ...)
17{
18 pb_syslog_message msg = {
19 .timestamp = platform_get_timestamp(),
20 .cpu_id = platform_current_cpu_id(),
21 };
22
23 msg.info.level = (syslog_level) level;
24 msg.info.featid = feat ? feat->id : 0;
28
29 if (thread)
30 {
31 msg.thread.tid = thread->tid;
32 msg.process.pid = thread->owner->pid;
33 strncpy(msg.thread.name, thread->name, sizeof(msg.thread.name));
34 strncpy(msg.process.name, thread->owner->name, sizeof(msg.process.name));
35 }
36
37 va_list args;
38 va_start(args, fmt);
39 vsnprintf(msg.message, sizeof(msg.message), fmt, args);
40 va_end(args);
41
43
44 if (level != MOS_LOG_UNSET)
45 {
46 lprintk(level, "\r\n");
47 if (feat)
48 lprintk(level, "%-10s | ", feat->name);
49
50#if MOS_CONFIG(MOS_PRINTK_WITH_TIMESTAMP)
51 lprintk(level, "%-16llu | ", platform_get_timestamp());
52#endif
53
54#if MOS_CONFIG(MOS_PRINTK_WITH_DATETIME)
55 lprintk(level, "%s | ", (const char *) platform_get_datetime_str());
56#endif
57
58#if MOS_CONFIG(MOS_PRINTK_WITH_CPU_ID)
59 lprintk(level, "cpu %2d | ", msg.cpu_id);
60#endif
61
62#if MOS_CONFIG(MOS_PRINTK_WITH_FILENAME)
63 lprintk(level, "%-15s | ", msg.info.source_location.filename);
64#endif
65
66#if MOS_CONFIG(MOS_PRINTK_WITH_THREAD_ID)
67 lprintk(level, "%pt\t| ", ((void *) thread));
68#endif
69 }
70
71 lprintk(level, "%s", msg.message);
72
74
75 return 0;
76}
u32 line
Definition assert.h:36
u32 const char * fmt
Definition assert.h:36
char args[3][16]
Definition avr_io.c:16
MOSAPI char * strncpy(char *__restrict dest, const char *__restrict src, size_t n)
Definition mos_string.c:202
MOSAPI int vsnprintf(char *__restrict buf, size_t size, const char *__restrict format, va_list args)
void lprintk(loglevel_t loglevel, const char *format,...)
Definition printk.c:111
u32 platform_current_cpu_id()
#define spinlock_acquire(lock)
Definition spinlock.h:61
#define SPINLOCK_INIT
Definition spinlock.h:28
#define spinlock_release(lock)
Definition spinlock.h:62
char name[32]
Definition syslog.pb.h:31
uint32_t pid
Definition syslog.pb.h:30
char filename[32]
Definition syslog.pb.h:35
char function[32]
Definition syslog.pb.h:37
pb_process process
Definition syslog.pb.h:51
pb_syslog_source_info info
Definition syslog.pb.h:48
uint32_t cpu_id
Definition syslog.pb.h:52
pb_thread thread
Definition syslog.pb.h:50
char message[512]
Definition syslog.pb.h:49
syslog_level level
Definition syslog.pb.h:41
pb_source_location source_location
Definition syslog.pb.h:43
uint32_t tid
Definition syslog.pb.h:25
char name[32]
Definition syslog.pb.h:26
const char * name
Definition task_types.h:46
pid_t pid
Definition task_types.h:45
const char * name
Definition task_types.h:78
process_t * owner
Definition task_types.h:79
tid_t tid
Definition task_types.h:77
static spinlock_t global_syslog_lock
Definition syslog.c:14
long do_syslog(loglevel_t level, thread_t *thread, const char *file, const char *func, int line, debug_info_entry *feat, const char *fmt,...)
Definition syslog.c:16
loglevel_t
Definition syslog.h:9
@ MOS_LOG_UNSET
Definition syslog.h:16
syslog_level
Definition syslog.pb.h:13
u64 platform_get_timestamp()
datetime_str_t * platform_get_datetime_str(void)