1//
2// LogFile_STD.cpp
3//
4// Library: Foundation
5// Package: Logging
6// Module: LogFile
7//
8// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/LogFile_STD.h"
16#include "Poco/File.h"
17#include "Poco/Exception.h"
18
19
20namespace Poco {
21
22
23LogFileImpl::LogFileImpl(const std::string& path):
24 _path(path),
25 _str(_path, std::ios::app),
26 _size((UInt64) _str.tellp())
27{
28 if (_size == 0)
29 _creationDate = File(path).getLastModified();
30 else
31 _creationDate = File(path).created();
32}
33
34
35LogFileImpl::~LogFileImpl()
36{
37}
38
39
40void LogFileImpl::writeImpl(const std::string& text, bool flush)
41{
42 if (!_str.good())
43 {
44 _str.close();
45 _str.open(_path, std::ios::app);
46 }
47 if (!_str.good()) throw WriteFileException(_path);
48 _str << text;
49 if (flush)
50 _str << std::endl;
51 else
52 _str << "\n";
53 if (!_str.good()) throw WriteFileException(_path);
54 _size = (UInt64) _str.tellp();
55}
56
57
58UInt64 LogFileImpl::sizeImpl() const
59{
60 return _size;
61}
62
63
64Timestamp LogFileImpl::creationDateImpl() const
65{
66 return _creationDate;
67}
68
69
70const std::string& LogFileImpl::pathImpl() const
71{
72 return _path;
73}
74
75
76} // namespace Poco
77