@@ -48,13 +48,6 @@ cl::opt<unsigned int> port{
4848 cl::desc (" The port to connect to" ),
4949};
5050
51- cl::opt<std::string> resource_dir{
52- " resource-dir" ,
53- cl::cat (category),
54- cl::value_desc (" path" ),
55- cl::desc (R"( The path of the clang resource directory, default is "../../lib/clang/version")" ),
56- };
57-
5851cl::opt<logging::ColorMode> log_color{
5952 " log-color" ,
6053 cl::cat (category),
@@ -69,75 +62,43 @@ cl::opt<logging::ColorMode> log_color{
6962cl::opt<logging::Level> log_level{
7063 " log-level" ,
7164 cl::cat (category),
72- cl::value_desc (" trace|debug|info|warn|fatal " ),
65+ cl::value_desc (" trace|debug|info|warn|error " ),
7366 cl::init (logging::Level::info),
7467 cl::values (clEnumValN (logging::Level::trace, " trace" , " " ),
7568 clEnumValN (logging::Level::debug, " debug" , " " ),
7669 clEnumValN (logging::Level::info, " info" , " " ),
7770 clEnumValN (logging::Level::warn, " warn" , " " ),
78- clEnumValN (logging::Level::err, " fatal" , " " )),
71+ clEnumValN (logging::Level::err, " error" , " " ),
72+ clEnumValN (logging::Level::off, " off" , " " )),
7973 cl::desc (" The log level, default is info" ),
8074};
8175
82- void init_log () {
83- using namespace logging ;
84- options.color = log_color;
85- options.level = log_level;
86- logging::create_stderr_logger (" clice" , logging::options);
87- }
88-
89- // / Check the command line arguments and initialize the clice.
90- bool check_arguments (int argc, const char ** argv) {
91- // / Hide unrelated options.
92- cl::HideUnrelatedOptions (category);
76+ } // namespace
9377
94- // Set version printer and parse command line options
78+ int main (int argc, const char ** argv) {
79+ llvm::InitLLVM guard (argc, argv);
80+ llvm::setBugReportMsg (
81+ " Please report bugs to https://github.com/clice-io/clice/issues and include the crash backtrace" );
9582 cl::SetVersionPrinter ([](llvm::raw_ostream& os) {
9683 os << std::format (" clice version: {}\n llvm version: {}\n " ,
9784 clice::config::version,
9885 clice::config::llvm_version);
9986 });
87+ cl::HideUnrelatedOptions (category);
10088 cl::ParseCommandLineOptions (argc,
10189 argv,
10290 " clice is a new generation of language server for C/C++" );
10391
104- init_log ();
92+ logging::options.color = log_color;
93+ logging::options.level = log_level;
94+ logging::stderr_logger (" clice" , logging::options);
10595
106- for ( int i = 0 ; i < argc; ++i ) {
107- logging::info ( " argv[{}] = {}" , i, argv[i] );
96+ if ( auto result = fs::init_resource_dir (argv[ 0 ]); !result ) {
97+ LOGGING_FATAL ( " Cannot find default resource directory, because {}" , result. error () );
10898 }
10999
110- // Initialize resource directory
111- if (resource_dir.empty ()) {
112- logging::info (" No resource directory specified, using default resource directory" );
113- // Try to initialize default resource directory
114- if (auto result = fs::init_resource_dir (argv[0 ]); !result) {
115- logging::warn (" Cannot find default resource directory, because {}" , result.error ());
116- return false ;
117- }
118- } else {
119- // Set and check the specified resource directory
120- fs::resource_dir = resource_dir.getValue ();
121- if (fs::exists (fs::resource_dir)) {
122- logging::info (" Resource directory found: {}" , fs::resource_dir);
123- } else {
124- logging::warn (" Resource directory not found: {}" , fs::resource_dir);
125- return false ;
126- }
127- }
128-
129- return true ;
130- }
131-
132- } // namespace
133-
134- int main (int argc, const char ** argv) {
135- llvm::InitLLVM guard (argc, argv);
136- llvm::setBugReportMsg (
137- " Please report bugs to https://github.com/clice-io/clice/issues and include the crash backtrace" );
138-
139- if (!check_arguments (argc, argv)) {
140- return 1 ;
100+ for (int i = 0 ; i < argc; ++i) {
101+ LOGGING_INFO (" argv[{}] = {}" , i, argv[i]);
141102 }
142103
143104 async::init ();
@@ -151,13 +112,13 @@ int main(int argc, const char** argv) {
151112 switch (mode) {
152113 case Mode::Pipe: {
153114 async::net::listen (loop);
154- logging::info (" Server starts listening on stdin/stdout" );
115+ LOGGING_INFO (" Server starts listening on stdin/stdout" );
155116 break ;
156117 }
157118
158119 case Mode::Socket: {
159120 async::net::listen (host.c_str (), port, loop);
160- logging::info (" Server starts listening on {}:{}" , host.getValue (), port.getValue ());
121+ LOGGING_INFO (" Server starts listening on {}:{}" , host.getValue (), port.getValue ());
161122 break ;
162123 }
163124
@@ -169,7 +130,7 @@ int main(int argc, const char** argv) {
169130
170131 async::run ();
171132
172- logging::info (" clice exit normally!" );
133+ LOGGING_INFO (" clice exit normally!" );
173134
174135 return 0 ;
175136}
0 commit comments