Mercurial > hg > orthanc
diff Core/FileStorage/FilesystemStorage.cpp @ 2087:e9e6ffbf0fd5
improved logging in FilesystemStorage
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Sep 2016 11:53:17 +0200 |
parents | 7a05144cb919 |
children | 0c09d1af22f3 |
line wrap: on
line diff
--- a/Core/FileStorage/FilesystemStorage.cpp Fri Sep 16 09:18:35 2016 +0200 +++ b/Core/FileStorage/FilesystemStorage.cpp Fri Sep 16 11:53:17 2016 +0200 @@ -86,11 +86,37 @@ Toolbox::MakeDirectory(root); } + + + static const char* GetDescriptionInternal(FileContentType content) + { + // This function is for logging only (internal use), a more + // fully-featured version is available in ServerEnumerations.cpp + switch (content) + { + case FileContentType_Unknown: + return "Unknown"; + + case FileContentType_Dicom: + return "DICOM"; + + case FileContentType_DicomAsJson: + return "JSON summary of DICOM"; + + default: + return "User-defined"; + } + } + + void FilesystemStorage::Create(const std::string& uuid, const void* content, size_t size, - FileContentType /*type*/) + FileContentType type) { + LOG(INFO) << "Creating attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type) + << "\" type (size: " << (size / (1024 * 1024) + 1) << "MB)"; + boost::filesystem::path path; path = GetPath(uuid); @@ -117,31 +143,17 @@ } } - boost::filesystem::ofstream f; - f.open(path, std::ofstream::out | std::ios::binary); - if (!f.good()) - { - throw OrthancException(ErrorCode_FileStorageCannotWrite); - } - - if (size != 0) - { - f.write(static_cast<const char*>(content), size); - if (!f.good()) - { - f.close(); - throw OrthancException(ErrorCode_FileStorageCannotWrite); - } - } - - f.close(); + Toolbox::WriteFile(content, size, path.string()); } void FilesystemStorage::Read(std::string& content, const std::string& uuid, - FileContentType /*type*/) + FileContentType type) { + LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type) + << "\" content type"; + content.clear(); Toolbox::ReadFile(content, GetPath(uuid).string()); } @@ -213,9 +225,7 @@ void FilesystemStorage::Remove(const std::string& uuid, FileContentType /*type*/) { -#if ORTHANC_ENABLE_GOOGLE_LOG == 1 - LOG(INFO) << "Deleting file " << uuid; -#endif + LOG(INFO) << "Deleting attachment \"" << uuid << "\""; namespace fs = boost::filesystem;