forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStdErrLogger.cpp
More file actions
51 lines (45 loc) · 1.39 KB
/
Copy pathStdErrLogger.cpp
File metadata and controls
51 lines (45 loc) · 1.39 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "winget/StdErrLogger.h"
namespace AppInstaller::Logging
{
namespace
{
static constexpr std::string_view s_StdErrLoggerName = "StdErrLogger";
}
std::string StdErrLogger::GetName() const
{
return std::string{ s_StdErrLoggerName };
}
void StdErrLogger::Write(Channel channel, Level level, std::string_view message) noexcept try
{
if (level >= m_level)
{
std::cerr << "<" << GetLevelChar(level) << "> [" << std::setw(GetMaxChannelNameLength()) << std::left << std::setfill(' ') << GetChannelName(channel) << "] " << message << std::endl;
}
}
catch (...)
{
// Just eat any exceptions here; better than losing logs
}
void StdErrLogger::WriteDirect(Channel, Level level, std::string_view message) noexcept try
{
if (level >= m_level)
{
std::cerr.write(message.data(), static_cast<std::streamsize>(message.size()));
}
}
catch (...)
{
// Just eat any exceptions here; better than losing logs
}
void StdErrLogger::Add()
{
Log().AddLogger(std::make_unique<StdErrLogger>());
}
void StdErrLogger::Remove()
{
Log().RemoveLogger(std::string{ s_StdErrLoggerName });
}
}