Начал реализовывать логирование
This commit is contained in:
parent
55e47f8310
commit
93d6581be7
42
include/logger.h
Normal file
42
include/logger.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#ifndef _LOGGER_H_
|
||||||
|
#define _LOGGER_H_
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
class logger
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::atomic<bool> _isLogging;
|
||||||
|
std::stringstream _logLine;
|
||||||
|
|
||||||
|
public:
|
||||||
|
logger();
|
||||||
|
void log(const char* s);
|
||||||
|
|
||||||
|
template<typename T, typename... Args> void log(const char* s, const T& value, const Args&... args)
|
||||||
|
{
|
||||||
|
if(!_isLogging)
|
||||||
|
{
|
||||||
|
_isLogging.store(true);
|
||||||
|
_logLine.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*s)
|
||||||
|
{
|
||||||
|
if (*s == '%' && *++s != '%')
|
||||||
|
{
|
||||||
|
_logLine << value;
|
||||||
|
return log(s, args...);
|
||||||
|
}
|
||||||
|
_logLine << *s++;
|
||||||
|
}
|
||||||
|
throw std::runtime_error("extra arguments provided");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern logger ulog;
|
||||||
|
|
||||||
|
#endif // _LOGGER_H_
|
||||||
@ -30,38 +30,44 @@ npos = -1
|
|||||||
|
|
||||||
_asm_ucs4_strstr:
|
_asm_ucs4_strstr:
|
||||||
|
|
||||||
xor r8, r8
|
push r12
|
||||||
mov r9d, dword [rdx]
|
mov r9d, dword [rdx]
|
||||||
|
mov rax, rdx
|
||||||
|
lea r8, [rdi + rsi*4]
|
||||||
|
lea r10, [rdx + rcx*4]
|
||||||
|
|
||||||
strstr_try_next_symbol:
|
strstr_try_next_symbol:
|
||||||
|
|
||||||
cmp r9d, dword [rdi + r8*4]
|
cmp r9d, dword [rdi]
|
||||||
je strstr_init_counter
|
je strstr_init_counter
|
||||||
inc r8
|
add rdi, 4
|
||||||
cmp rsi, r8
|
cmp rdi, r8
|
||||||
jne strstr_try_next_symbol
|
jne strstr_try_next_symbol
|
||||||
|
pop r12
|
||||||
mov rax, 0
|
mov rax, 0
|
||||||
ret
|
ret
|
||||||
|
|
||||||
strstr_init_counter:
|
strstr_init_counter:
|
||||||
|
|
||||||
xor r10, r10
|
mov rdx, rax
|
||||||
|
mov r12, rdi
|
||||||
|
|
||||||
strstr_symbol_found:
|
strstr_symbol_found:
|
||||||
|
|
||||||
inc r10
|
add rdx, 4
|
||||||
cmp r10, rcx
|
cmp rdx, r10
|
||||||
je strstr_the_end
|
je strstr_the_end
|
||||||
lea rax, [r8 + r10]
|
add r12, 4
|
||||||
mov r11d, dword [rdi + rax*4]
|
mov r11d, dword [r12]
|
||||||
cmp r11d, dword [rdx + r10*4]
|
cmp r11d, dword [rdx]
|
||||||
je strstr_symbol_found
|
je strstr_symbol_found
|
||||||
inc r8
|
add rdi, 4
|
||||||
jmp strstr_try_next_symbol
|
jmp strstr_try_next_symbol
|
||||||
|
|
||||||
strstr_the_end:
|
strstr_the_end:
|
||||||
|
|
||||||
lea rax, [rdi + r8*4]
|
pop r12
|
||||||
|
mov rax, rdi
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|||||||
30
src/logger.cpp
Normal file
30
src/logger.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
logger ulog;
|
||||||
|
|
||||||
|
logger::logger(): _isLogging(ATOMIC_FLAG_INIT)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void logger::log(const char *s)
|
||||||
|
{
|
||||||
|
if(!_isLogging)
|
||||||
|
{
|
||||||
|
_isLogging.store(true);
|
||||||
|
_logLine.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*s)
|
||||||
|
{
|
||||||
|
if (*s == '%' && *++s != '%')
|
||||||
|
throw std::runtime_error("invalid format string: missing arguments");
|
||||||
|
_logLine << *s++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << _logLine.str() << std::endl;
|
||||||
|
|
||||||
|
_isLogging.store(false);
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,5 +1,6 @@
|
|||||||
#include "ustring.h"
|
#include "ustring.h"
|
||||||
#include "utf.h"
|
#include "utf.h"
|
||||||
|
#include "logger.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -562,6 +563,6 @@ TEST(Ustring, replace_string)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user