LogFile_VMS.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // LogFile_VMS.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/LogFile_VMS.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Logging
  8. // Module: LogFile
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/LogFile_VMS.h"
  16. #include "Poco/File.h"
  17. #include "Poco/Exception.h"
  18. namespace Poco {
  19. LogFileImpl::LogFileImpl(const std::string& path): _path(path)
  20. {
  21. _file = fopen(path.c_str(), "a", "ctx=rec,bin", "shr=get", "fop=dfw", "alq=500", "deq=500");
  22. if (!_file) throw OpenFileException(path);
  23. if (size() == 0)
  24. _creationDate = File(path).getLastModified();
  25. else
  26. _creationDate = File(path).created();
  27. }
  28. LogFileImpl::~LogFileImpl()
  29. {
  30. fclose(_file);
  31. }
  32. void LogFileImpl::writeImpl(const std::string& text, bool flush)
  33. {
  34. int rc = fputs(text.c_str(), _file);
  35. if (rc == EOF) throw WriteFileException(_path);
  36. rc = fputc('\n', _file);
  37. if (rc == EOF) throw WriteFileException(_path);
  38. if (flush)
  39. {
  40. rc = fflush(_file);
  41. if (rc == EOF) throw WriteFileException(_path);
  42. }
  43. }
  44. UInt64 LogFileImpl::sizeImpl() const
  45. {
  46. return (UInt64) ftell(_file);
  47. }
  48. Timestamp LogFileImpl::creationDateImpl() const
  49. {
  50. return _creationDate;
  51. }
  52. const std::string& LogFileImpl::pathImpl() const
  53. {
  54. return _path;
  55. }
  56. } // namespace Poco