Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
c5c6baad
Commit
c5c6baad
authored
Jul 15, 2016
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added errno description to sdlog exception strings
parent
e5032c8d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
7 deletions
+45
-7
include/spdlog/common.h
include/spdlog/common.h
+7
-0
include/spdlog/details/file_helper.h
include/spdlog/details/file_helper.h
+6
-5
include/spdlog/details/os.h
include/spdlog/details/os.h
+29
-0
include/spdlog/sinks/file_sinks.h
include/spdlog/sinks/file_sinks.h
+3
-2
No files found.
include/spdlog/common.h
View file @
c5c6baad
...
@@ -100,10 +100,17 @@ enum class async_overflow_policy
...
@@ -100,10 +100,17 @@ enum class async_overflow_policy
//
//
// Log exception
// Log exception
//
//
namespace
details
{
namespace
os
{
std
::
string
errno_str
(
int
err_num
);
}}
class
spdlog_ex
:
public
std
::
exception
class
spdlog_ex
:
public
std
::
exception
{
{
public:
public:
spdlog_ex
(
const
std
::
string
&
msg
)
:
_msg
(
msg
)
{}
spdlog_ex
(
const
std
::
string
&
msg
)
:
_msg
(
msg
)
{}
spdlog_ex
(
const
std
::
string
&
msg
,
int
last_errno
)
{
_msg
=
msg
+
": "
+
details
::
os
::
errno_str
(
last_errno
);
}
const
char
*
what
()
const
SPDLOG_NOEXCEPT
override
const
char
*
what
()
const
SPDLOG_NOEXCEPT
override
{
{
return
_msg
.
c_str
();
return
_msg
.
c_str
();
...
...
include/spdlog/details/file_helper.h
View file @
c5c6baad
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include <cstdio>
#include <cstdio>
#include <string>
#include <string>
#include <thread>
#include <thread>
#include <cerrno>
namespace
spdlog
namespace
spdlog
{
{
...
@@ -58,7 +59,7 @@ public:
...
@@ -58,7 +59,7 @@ public:
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
open_interval
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
open_interval
));
}
}
throw
spdlog_ex
(
"Failed opening file "
+
os
::
filename_to_str
(
_filename
)
+
" for writing"
);
throw
spdlog_ex
(
"Failed opening file "
+
os
::
filename_to_str
(
_filename
)
+
" for writing"
,
errno
);
}
}
void
reopen
(
bool
truncate
)
void
reopen
(
bool
truncate
)
...
@@ -89,7 +90,7 @@ public:
...
@@ -89,7 +90,7 @@ public:
size_t
msg_size
=
msg
.
formatted
.
size
();
size_t
msg_size
=
msg
.
formatted
.
size
();
auto
data
=
msg
.
formatted
.
data
();
auto
data
=
msg
.
formatted
.
data
();
if
(
std
::
fwrite
(
data
,
1
,
msg_size
,
_fd
)
!=
msg_size
)
if
(
std
::
fwrite
(
data
,
1
,
msg_size
,
_fd
)
!=
msg_size
)
throw
spdlog_ex
(
"Failed writing to file "
+
os
::
filename_to_str
(
_filename
));
throw
spdlog_ex
(
"Failed writing to file "
+
os
::
filename_to_str
(
_filename
)
,
errno
);
if
(
_force_flush
)
if
(
_force_flush
)
std
::
fflush
(
_fd
);
std
::
fflush
(
_fd
);
...
@@ -102,15 +103,15 @@ public:
...
@@ -102,15 +103,15 @@ public:
auto
pos
=
ftell
(
_fd
);
auto
pos
=
ftell
(
_fd
);
if
(
fseek
(
_fd
,
0
,
SEEK_END
)
!=
0
)
if
(
fseek
(
_fd
,
0
,
SEEK_END
)
!=
0
)
throw
spdlog_ex
(
"fseek failed on file "
+
os
::
filename_to_str
(
_filename
));
throw
spdlog_ex
(
"fseek failed on file "
+
os
::
filename_to_str
(
_filename
)
,
errno
);
auto
file_size
=
ftell
(
_fd
);
auto
file_size
=
ftell
(
_fd
);
if
(
fseek
(
_fd
,
pos
,
SEEK_SET
)
!=
0
)
if
(
fseek
(
_fd
,
pos
,
SEEK_SET
)
!=
0
)
throw
spdlog_ex
(
"fseek failed on file "
+
os
::
filename_to_str
(
_filename
));
throw
spdlog_ex
(
"fseek failed on file "
+
os
::
filename_to_str
(
_filename
)
,
errno
);
if
(
file_size
==
-
1
)
if
(
file_size
==
-
1
)
throw
spdlog_ex
(
"ftell failed on file "
+
os
::
filename_to_str
(
_filename
));
throw
spdlog_ex
(
"ftell failed on file "
+
os
::
filename_to_str
(
_filename
)
,
errno
);
return
file_size
;
return
file_size
;
}
}
...
...
include/spdlog/details/os.h
View file @
c5c6baad
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include <ctime>
#include <ctime>
#include <functional>
#include <functional>
#include <string>
#include <string>
#include <string.h>
#ifdef _WIN32
#ifdef _WIN32
...
@@ -27,12 +28,16 @@
...
@@ -27,12 +28,16 @@
#endif
#endif
#elif __linux__
#elif __linux__
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#include <sys/stat.h>
#include <sys/stat.h>
#include <unistd.h>
#include <unistd.h>
#include <chrono>
#include <chrono>
#else
#else
#include <thread>
#include <thread>
#endif
#endif
namespace
spdlog
namespace
spdlog
...
@@ -246,6 +251,30 @@ inline std::string filename_to_str(const filename_t& filename)
...
@@ -246,6 +251,30 @@ inline std::string filename_to_str(const filename_t& filename)
}
}
#endif
#endif
// Return errno string (thread safe)
inline
std
::
string
errno_str
(
int
err_num
)
{
char
buf
[
256
];
constexpr
auto
buf_size
=
sizeof
(
buf
);
#ifdef _WIN32
if
(
strerror_s
(
buf
,
buf_size
,
err_num
)
==
0
)
return
std
::
string
(
buf
);
else
return
"Unkown error"
;
#elif (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE // posix version
if
(
strerror_r
(
err_num
,
buf
,
buf_size
)
==
0
)
return
std
::
string
(
buf
);
else
return
"Unkown error"
;
#else // gnu version (might not use the given buf, so its retval pointer must be used)
return
std
::
string
(
strerror_r
(
err_num
,
buf
,
buf_size
));
#endif
}
}
//os
}
//os
}
//details
}
//details
}
//spdlog
}
//spdlog
...
...
include/spdlog/sinks/file_sinks.h
View file @
c5c6baad
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#include <ctime>
#include <ctime>
#include <mutex>
#include <mutex>
#include <string>
#include <string>
#include <cerrno>
namespace
spdlog
namespace
spdlog
{
{
...
@@ -119,12 +120,12 @@ private:
...
@@ -119,12 +120,12 @@ private:
{
{
if
(
details
::
os
::
remove
(
target
)
!=
0
)
if
(
details
::
os
::
remove
(
target
)
!=
0
)
{
{
throw
spdlog_ex
(
"rotating_file_sink: failed removing "
+
filename_to_str
(
target
));
throw
spdlog_ex
(
"rotating_file_sink: failed removing "
+
filename_to_str
(
target
)
,
errno
);
}
}
}
}
if
(
details
::
file_helper
::
file_exists
(
src
)
&&
details
::
os
::
rename
(
src
,
target
))
if
(
details
::
file_helper
::
file_exists
(
src
)
&&
details
::
os
::
rename
(
src
,
target
))
{
{
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
filename_to_str
(
src
)
+
" to "
+
filename_to_str
(
target
));
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
filename_to_str
(
src
)
+
" to "
+
filename_to_str
(
target
)
,
errno
);
}
}
}
}
_file_helper
.
reopen
(
true
);
_file_helper
.
reopen
(
true
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment