Skip to content

Commit

Permalink
Merge pull request #1933 from JakubSosnovec/iox-1932-fix-log-timestam…
Browse files Browse the repository at this point in the history
…p-conversion

iox-1932 Fix log timestamp conversion
  • Loading branch information
elBoberido authored Mar 1, 2023
2 parents 619514f + 1b85ff4 commit adbed1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
- Can not build iceoryx with gcc 9.4 [\#1871](https://github.com/eclipse-iceoryx/iceoryx/issues/1871)
- Update iceoryx_integrationtest package to use ROS2 Humble [\#1906](https://github.com/eclipse-iceoryx/iceoryx/issues/1906)
- Fix potential memory leak in `iox::stack` [\#1893](https://github.com/eclipse-iceoryx/iceoryx/issues/1893)
- Fix milliseconds in log timestamps [\#1932](https://github.com/eclipse-iceoryx/iceoryx/issues/1932)

**Refactoring:**

Expand Down
7 changes: 5 additions & 2 deletions iceoryx_hoofs/source/log/building_blocks/console_logger.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2023 by NXP. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,8 +107,10 @@ void ConsoleLogger::createLogMessageHeader(const char* file,
strncpy(&timestampString[0], &TIME_FORMAT[0], ConsoleLogger::bufferSize(TIME_FORMAT));
}

constexpr uint32_t MILLISECS_PER_SECOND{1000};
const auto milliseconds = static_cast<int32_t>(timestamp.tv_nsec % MILLISECS_PER_SECOND);
constexpr uint32_t MILLISECS_PER_SEC{1000};
constexpr uint32_t NANOSECS_PER_MILLISEC{1000000};
// convert nanoseconds to milliseconds and compute the remaining milliseconds in a second
const auto milliseconds = static_cast<int32_t>((timestamp.tv_nsec / NANOSECS_PER_MILLISEC) % MILLISECS_PER_SEC);

/// @todo iox-#1755 do we also want to always log the iceoryx version and commit sha? Maybe do that only in
/// 'initLogger' with LogDebug
Expand Down

0 comments on commit adbed1b

Please sign in to comment.