Logging improvements to allow prettier displays in the server GUI.
[dcpomatic.git] / src / lib / environment_info.cc
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "log.h"
21 #include "compose.hpp"
22 #include "version.h"
23 #include "cross.h"
24 #include <dcp/version.h>
25 #include <openjpeg.h>
26 #include <libssh/libssh.h>
27 #ifdef DCPOMATIC_IMAGE_MAGICK
28 #include <magick/MagickCore.h>
29 #else
30 #include <magick/common.h>
31 #include <magick/magick_config.h>
32 #endif
33 #include <magick/version.h>
34 extern "C" {
35 #include <libavcodec/avcodec.h>
36 #include <libavformat/avformat.h>
37 #include <libswscale/swscale.h>
38 #include <libavfilter/avfiltergraph.h>
39 #include <libavutil/pixfmt.h>
40 }
41 #include <boost/thread.hpp>
42
43 #include "i18n.h"
44
45 #define LOG_GENERAL(...) log->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
46 #define LOG_GENERAL_NC(...) log->log (__VA_ARGS__, LogEntry::TYPE_GENERAL);
47
48 using std::string;
49 using std::list;
50 using std::pair;
51 using boost::shared_ptr;
52
53 /** @param v Version as used by FFmpeg.
54  *  @return A string representation of v.
55  */
56 static
57 string
58 ffmpeg_version_to_string (int v)
59 {
60         SafeStringStream s;
61         s << ((v & 0xff0000) >> 16) << N_(".") << ((v & 0xff00) >> 8) << N_(".") << (v & 0xff);
62         return s.str ();
63 }
64
65
66 /** Return a user-readable string summarising the versions of our dependencies */
67 static
68 string
69 dependency_version_summary ()
70 {
71         SafeStringStream s;
72         s << N_("libopenjpeg ") << opj_version () << N_(", ")
73           << N_("libavcodec ") << ffmpeg_version_to_string (avcodec_version()) << N_(", ")
74           << N_("libavfilter ") << ffmpeg_version_to_string (avfilter_version()) << N_(", ")
75           << N_("libavformat ") << ffmpeg_version_to_string (avformat_version()) << N_(", ")
76           << N_("libavutil ") << ffmpeg_version_to_string (avutil_version()) << N_(", ")
77           << N_("libswscale ") << ffmpeg_version_to_string (swscale_version()) << N_(", ")
78           << MagickVersion << N_(", ")
79           << N_("libssh ") << ssh_version (0) << N_(", ")
80           << N_("libdcp ") << dcp::version << N_(" git ") << dcp::git_commit;
81
82         return s.str ();
83 }
84
85 void
86 environment_info (shared_ptr<Log> log)
87 {
88         LOG_GENERAL ("DCP-o-matic %1 git %2 using %3", dcpomatic_version, dcpomatic_git_commit, dependency_version_summary());
89
90         {
91                 char buffer[128];
92                 gethostname (buffer, sizeof (buffer));
93                 LOG_GENERAL ("Host name %1", buffer);
94         }
95
96 #ifdef DCPOMATIC_DEBUG
97         LOG_GENERAL_NC ("DCP-o-matic built in debug mode.");
98 #else
99         LOG_GENERAL_NC ("DCP-o-matic built in optimised mode.");
100 #endif
101 #ifdef LIBDCP_DEBUG
102         LOG_GENERAL_NC ("libdcp built in debug mode.");
103 #else
104         LOG_GENERAL_NC ("libdcp built in optimised mode.");
105 #endif
106
107 #ifdef DCPOMATIC_WINDOWS
108         OSVERSIONINFO info;
109         info.dwOSVersionInfoSize = sizeof (info);
110         GetVersionEx (&info);
111         LOG_GENERAL ("Windows version %1.%2.%3 SP %4", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber, info.szCSDVersion);
112 #endif
113
114 #if __GNUC__
115 #if __x86_64__
116         LOG_GENERAL_NC ("Built for 64-bit");
117 #else
118         LOG_GENERAL_NC ("Built for 32-bit");
119 #endif
120 #endif
121
122         LOG_GENERAL ("CPU: %1, %2 processors", cpu_info(), boost::thread::hardware_concurrency ());
123         list<pair<string, string> > const m = mount_info ();
124         for (list<pair<string, string> >::const_iterator i = m.begin(); i != m.end(); ++i) {
125                 LOG_GENERAL ("Mount: %1 %2", i->first, i->second);
126         }
127 }