master
h 50 lines 1.75 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2 #pragma once
3
4 #include <string>
5
6 // Trace-logging levels that match the levels used by Windows levels.
7 #define TRACE_LEVEL_NONE 0 // Tracing is not on
8 #define TRACE_LEVEL_CRITICAL 1 // Abnormal exit or termination
9 #define TRACE_LEVEL_ERROR 2 // Severe errors that need logging
10 #define TRACE_LEVEL_WARNING 3 // Warnings such as allocation failure
11 #define TRACE_LEVEL_INFORMATION 4 // Includes non-error cases(e.g.,Entry-Exit)
12 #define TRACE_LEVEL_VERBOSE 5 // Detailed traces from intermediate steps
13
14 #if defined(__cplusplus)
15
16 namespace p9fs {
17
18 // Tracelogging class that has similar methods as its Windows counterpart to simple log statements
19 // in the cross-platform code will work.
20 class Plan9TraceLoggingProvider
21 {
22 public:
23 static void SetLogFileDescriptor(int fd);
24 static bool IsEnabled(int level);
25 static void SetLevel(int level);
26 static void LogMessage(const char* message, int level = TRACE_LEVEL_VERBOSE);
27 static void LogMessage(const std::string& message, int level = TRACE_LEVEL_VERBOSE);
28 static void LogException(const char* message, const char* exceptionDescription, int level = TRACE_LEVEL_ERROR);
29 static void ServerStart();
30 static void ServerStop();
31 static void AcceptedConnection();
32 static void ConnectionDisconnected();
33 static void TooManyConnections();
34 static void InvalidResponseBufferSize();
35 static void PreAccept();
36 static void PostAccept();
37 static void OperationAborted();
38 static void ClientConnected(unsigned int connectionCount);
39 static void ClientDisconnected(unsigned int connectionCount);
40
41 private:
42 Plan9TraceLoggingProvider() = delete;
43
44 static int m_level;
45 static int m_log;
46 };
47
48 } // namespace p9fs
49
50 #endif