mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[libj6] Add formatting j6::syslog wrapper for j6_log
To replace all the places where snprintf/j6_log are called with buffers on the stack for most frames.
This commit is contained in:
@@ -8,6 +8,7 @@ j6 = module("j6",
|
|||||||
"protocol_ids.cpp",
|
"protocol_ids.cpp",
|
||||||
"syscalls.s.cog",
|
"syscalls.s.cog",
|
||||||
"sysconf.cpp.cog",
|
"sysconf.cpp.cog",
|
||||||
|
"syslog.cpp",
|
||||||
"thread.cpp",
|
"thread.cpp",
|
||||||
],
|
],
|
||||||
public_headers = [
|
public_headers = [
|
||||||
@@ -19,6 +20,7 @@ j6 = module("j6",
|
|||||||
"j6/protocols/service_locator.h",
|
"j6/protocols/service_locator.h",
|
||||||
"j6/syscalls.h.cog",
|
"j6/syscalls.h.cog",
|
||||||
"j6/sysconf.h.cog",
|
"j6/sysconf.h.cog",
|
||||||
|
"j6/syslog.hh",
|
||||||
"j6/thread.hh",
|
"j6/thread.hh",
|
||||||
"j6/types.h",
|
"j6/types.h",
|
||||||
|
|
||||||
|
|||||||
15
src/libraries/j6/j6/syslog.hh
Normal file
15
src/libraries/j6/j6/syslog.hh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
/// \file j6/syslog.hh
|
||||||
|
/// Utility function for writing messages to the kernel log
|
||||||
|
|
||||||
|
// The kernel depends on libj6 for some shared code,
|
||||||
|
// but should not include the user-specific code.
|
||||||
|
#ifndef __j6kernel
|
||||||
|
|
||||||
|
namespace j6 {
|
||||||
|
|
||||||
|
void syslog(const char *fmt, ...);
|
||||||
|
|
||||||
|
} // namespace j6
|
||||||
|
|
||||||
|
#endif // __j6kernel
|
||||||
26
src/libraries/j6/syslog.cpp
Normal file
26
src/libraries/j6/syslog.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// The kernel depends on libj6 for some shared code,
|
||||||
|
// but should not include the user-specific code.
|
||||||
|
#ifndef __j6kernel
|
||||||
|
|
||||||
|
#include <util/format.h>
|
||||||
|
#include <j6/syscalls.h>
|
||||||
|
|
||||||
|
namespace j6 {
|
||||||
|
|
||||||
|
void
|
||||||
|
syslog(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buffer[200];
|
||||||
|
|
||||||
|
va_list va;
|
||||||
|
va_start(va, fmt);
|
||||||
|
size_t n = util::vformat({buffer, sizeof(buffer) - 1}, fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
|
||||||
|
buffer[n] = 0;
|
||||||
|
j6_log(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace j6
|
||||||
|
|
||||||
|
#endif // __j6kernel
|
||||||
Reference in New Issue
Block a user