v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
globals.h
Go to the documentation of this file.
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_TORQUE_LS_GLOBALS_H_
6#define V8_TORQUE_LS_GLOBALS_H_
7
8#include <fstream>
9
10#include "src/base/contextual.h"
11
12namespace v8 {
13namespace internal {
14namespace torque {
15
16// When the language server is run by VS code, stdout can not be seen, as it is
17// used as the communication channel. For debugging purposes a simple
18// Log class is added, that allows writing diagnostics to a file configurable
19// via command line flag.
20class Logger : public base::ContextualClass<Logger> {
21 public:
22 Logger() : enabled_(false) {}
24 if (enabled_) logfile_.close();
25 }
26
27 static void Enable(std::string path) {
28 Get().enabled_ = true;
29 Get().logfile_.open(path);
30 }
31
32 template <class... Args>
33 static void Log(Args&&... args) {
34 if (Enabled()) {
35 USE((Stream() << std::forward<Args>(args))...);
36 Flush();
37 }
38 }
39
40 private:
41 static bool Enabled() { return Get().enabled_; }
42 static std::ofstream& Stream() {
44 return Get().logfile_;
45 }
46 static void Flush() { Get().logfile_.flush(); }
47
48 private:
50 std::ofstream logfile_;
51};
52
53DECLARE_CONTEXTUAL_VARIABLE(TorqueFileList, std::vector<std::string>);
54
55} // namespace torque
56} // namespace internal
57} // namespace v8
58
59#endif // V8_TORQUE_LS_GLOBALS_H_
static VarType & Get()
Definition contextual.h:64
static void Log(Args &&... args)
Definition globals.h:33
static void Enable(std::string path)
Definition globals.h:27
static std::ofstream & Stream()
Definition globals.h:42
#define DECLARE_CONTEXTUAL_VARIABLE(VarName,...)
Definition contextual.h:88
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
#define CHECK(condition)
Definition logging.h:124
#define USE(...)
Definition macros.h:293