QsLogDest.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2013, Razvan Petru
  2. // All rights reserved.
  3. // Redistribution and use in source and binary forms, with or without modification,
  4. // are permitted provided that the following conditions are met:
  5. // * Redistributions of source code must retain the above copyright notice, this
  6. // list of conditions and the following disclaimer.
  7. // * Redistributions in binary form must reproduce the above copyright notice, this
  8. // list of conditions and the following disclaimer in the documentation and/or other
  9. // materials provided with the distribution.
  10. // * The name of the contributors may not be used to endorse or promote products
  11. // derived from this software without specific prior written permission.
  12. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  13. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  16. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  17. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  18. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  20. // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  21. // OF THE POSSIBILITY OF SUCH DAMAGE.
  22. #include "QsLogDest.h"
  23. #include "QsLogDestConsole.h"
  24. #include "QsLogDestFile.h"
  25. #include "QsLogDestFunctor.h"
  26. #include <QString>
  27. namespace QsLogging
  28. {
  29. Destination::~Destination()
  30. {
  31. }
  32. //! destination factory
  33. DestinationPtr DestinationFactory::MakeFileDestination(const QString& filePath,
  34. LogRotationOption rotation, const MaxSizeBytes &sizeInBytesToRotateAfter,
  35. const MaxOldLogCount &oldLogsToKeep)
  36. {
  37. if (EnableLogRotation == rotation || EnableLogRotationOnOpen == rotation) {
  38. QScopedPointer<SizeRotationStrategy> logRotation(new SizeRotationStrategy);
  39. logRotation->setMaximumSizeInBytes(sizeInBytesToRotateAfter.size);
  40. logRotation->setBackupCount(oldLogsToKeep.count);
  41. FileDestination *dest = new FileDestination(filePath, RotationStrategyPtr(logRotation.take()));
  42. if (EnableLogRotationOnOpen == rotation && dest->rotationStrategy()->currentSizeInBytes() > 0)
  43. dest->rotate();
  44. return DestinationPtr(dest);
  45. }
  46. return DestinationPtr(new FileDestination(filePath, RotationStrategyPtr(new NullRotationStrategy)));
  47. }
  48. DestinationPtr DestinationFactory::MakeDebugOutputDestination()
  49. {
  50. return DestinationPtr(new DebugOutputDestination);
  51. }
  52. DestinationPtr DestinationFactory::MakeFunctorDestination(QsLogging::Destination::LogFunction f)
  53. {
  54. return DestinationPtr(new FunctorDestination(f));
  55. }
  56. DestinationPtr DestinationFactory::MakeFunctorDestination(QObject *receiver, const char *member)
  57. {
  58. return DestinationPtr(new FunctorDestination(receiver, member));
  59. }
  60. } // end namespace