-
Notifications
You must be signed in to change notification settings - Fork 3
/
e-PrintfStyleLogging.cpp
59 lines (51 loc) · 1.43 KB
/
e-PrintfStyleLogging.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Borislav Stanimirov
// SPDX-License-Identifier: MIT
//
#include <jalog/Instance.hpp>
#include <jalog/sinks/DefaultSink.hpp>
#include <jalog/Scope.hpp>
#include <jalog/Log.hpp>
#include <jalog/Printf.hpp>
///////////////////////////////////////////////////////////////////////////////
// this is an imaginary c library
typedef void(*clib_log_func)(const char* fmt, ...);
clib_log_func clib_log_info;
clib_log_func clib_log_error;
void clib_do_x(int x)
{
if (clib_log_info) clib_log_info("Doing X: %d", x);
// ...
}
void clib_do_y(double y)
{
if (clib_log_info) clib_log_info("Doing something else: %.3f", y);
if (clib_log_error) clib_log_error("Uh-oh. An error has occured: %s", "y is bad");
// ...
}
///////////////////////////////////////////////////////////////////////////////
jalog::Scope clibScope("clib");
void JalogForCLib_Info(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
jalog::VPrintf(clibScope, jalog::Level::Info, fmt, args);
va_end(args);
}
void JalogForCLib_Error(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
jalog::VPrintf(clibScope, jalog::Level::Error, fmt, args);
va_end(args);
}
int main()
{
jalog::Instance jl;
jl.setup().add<jalog::sinks::DefaultSink>();
clib_log_info = JalogForCLib_Info;
clib_log_error = JalogForCLib_Error;
JALOG(Info, "Launching CLib");
clib_do_x(43);
clib_do_y(3.141592);
return 0;
}