Pteros  2.0
Molecular modeling library for human beings!
logging.h
1 /*
2  * This file is a part of
3  *
4  * ============================================
5  * ### Pteros molecular modeling library ###
6  * ============================================
7  *
8  * https://github.com/yesint/pteros
9  *
10  * (C) 2009-2021, Semen Yesylevskyy
11  *
12  * All works, which use Pteros, should cite the following papers:
13  *
14  * 1. Semen O. Yesylevskyy, "Pteros 2.0: Evolution of the fast parallel
15  * molecular analysis library for C++ and python",
16  * Journal of Computational Chemistry, 2015, 36(19), 1480–1488.
17  * doi: 10.1002/jcc.23943.
18  *
19  * 2. Semen O. Yesylevskyy, "Pteros: Fast and easy to use open-source C++
20  * library for molecular analysis",
21  * Journal of Computational Chemistry, 2012, 33(19), 1632–1636.
22  * doi: 10.1002/jcc.22989.
23  *
24  * This is free software distributed under Artistic License:
25  * http://www.opensource.org/licenses/artistic-license-2.0.php
26  *
27 */
28 
29 
30 #pragma once
31 
32 #include "spdlog/spdlog.h"
33 #include "fmt/ostream.h"
34 #include "spdlog/sinks/stdout_sinks.h"
35 #include <iostream>
36 
37 namespace pteros {
38 
39 decltype(spdlog::details::registry::instance()) get_registry();
40 
41 class Log
42 {
43 public:
44  static Log& instance()
45  {
46  static Log *instance = new Log();
47  return *instance;
48  }
49 
50  std::shared_ptr<spdlog::logger> logger;
51  std::shared_ptr<spdlog::sinks::stdout_sink_st> console_sink;
52  std::string generic_pattern;
53  spdlog::level::level_enum default_level;
54 
55 private:
56  Log() {
57  generic_pattern = "[%n]\t(%l)\t%v";
58  default_level = spdlog::level::info;
59  try {
60  console_sink = std::make_shared<spdlog::sinks::stdout_sink_st>();
61  logger = std::make_shared<spdlog::logger>("pteros", console_sink);
62  logger->set_pattern(generic_pattern);
63  logger->set_level(default_level);
64  spdlog::register_logger(logger);
65  } catch (const spdlog::spdlog_ex& ex) {
66  std::cout << "Log initialization failed: " << ex.what() << std::endl;
67  }
68  }
69 };
70 
71 std::shared_ptr<spdlog::logger> create_logger(const std::string& name);
72 
73 void set_log_level(const std::string& lev);
74 
75 }
76 
77 #define LOG() (Log::instance().logger)
78 
79 
80