-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cc
57 lines (49 loc) · 1.98 KB
/
main.cc
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
52
53
54
55
56
57
// Copyright (c) 2014 The Caroline authors. All rights reserved.
// Use of this source file is governed by a MIT license that can be found in the
// LICENSE file.
/// @author Aleksandr Derbenev <[email protected]>
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "core/application_factory.h"
#include "core/caroline.h"
#include "core/preferences_service.h"
#include "core/switches.h"
#include "core/time_utils.h"
#include "core/return_codes.h"
/// Entry point of the program.
/// @param argc Number of command line arguments.
/// @param argv nullptr terminated list of command line arguments.
/// @returns 0 on success.
int main(int argc, const char* argv[]) {
base::AtExitManager at_exit_manager;
base::PathService::Init(*argv);
new core::TimeLog();
auto command_line(base::CommandLine::GetForCurrentProcess());
base::CommandLine::ParseArgs(argv, command_line.get());
core::PrefService::Init();
if (command_line->HasSwitch(core::switches::kEnableLogging)) {
std::string level =
command_line->GetSwitchData(core::switches::kEnableLogging);
base::Logger::Level minimal_level = base::Logger::LOG_INFO;
if (base::Logger::kLevelError == level)
minimal_level = base::Logger::LOG_ERROR;
else if (base::Logger::kLevelWarning == level)
minimal_level = base::Logger::LOG_WARNING;
else if (base::Logger::kLevelInfo == level)
minimal_level = base::Logger::LOG_INFO;
else if (base::Logger::kLevelDebug == level)
minimal_level = base::Logger::LOG_DEBUG;
else if (base::Logger::kLevelNone == level)
minimal_level = base::Logger::LOG_NONE;
std::string file =
command_line->GetSwitchData(core::switches::kLogFile);
base::Logger::Init(file, minimal_level);
}
std::unique_ptr<core::Caroline> application(
core::CreateApplication(command_line.get()));
if (!application->Init())
return core::RETURN_APPLICATION_INIT_FAIL;
return application->Run();
}