LogFile_STD.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // LogFile_STD.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/LogFile_STD.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_STD.h"
  16. #include "Poco/File.h"
  17. #include "Poco/Exception.h"
  18. namespace Poco {
  19. LogFileImpl::LogFileImpl(const std::string& path):
  20. _path(path),
  21. _str(_path, std::ios::app)
  22. {
  23. if (sizeImpl() == 0)
  24. _creationDate = File(path).getLastModified();
  25. else
  26. _creationDate = File(path).created();
  27. }
  28. LogFileImpl::~LogFileImpl()
  29. {
  30. }
  31. void LogFileImpl::writeImpl(const std::string& text, bool flush)
  32. {
  33. _str << text;
  34. if (flush)
  35. _str << std::endl;
  36. else
  37. _str << "\n";
  38. if (!_str.good()) throw WriteFileException(_path);
  39. }
  40. UInt64 LogFileImpl::sizeImpl() const
  41. {
  42. return (UInt64) _str.tellp();
  43. }
  44. Timestamp LogFileImpl::creationDateImpl() const
  45. {
  46. return _creationDate;
  47. }
  48. const std::string& LogFileImpl::pathImpl() const
  49. {
  50. return _path;
  51. }
  52. } // namespace Poco