1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "texgine/utils/exlog.h" 17 18 #include <chrono> 19 #include <ctime> 20 #include <iomanip> 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace TextEngine { ExTime(Logger & algnlogger,enum Logger::LOG_PHASE phase)25void ExTime(Logger &algnlogger, enum Logger::LOG_PHASE phase) 26 { 27 if (phase == Logger::LOG_PHASE::BEGIN) { 28 auto timer = time(nullptr); 29 auto now = localtime(&timer); 30 if (now == nullptr) { 31 return; 32 } 33 int64_t nowMs = std::chrono::duration_cast<std::chrono::milliseconds>( 34 std::chrono::system_clock::now().time_since_epoch()).count() + (8 * 1000LL * 60 * 60); 35 int year = static_cast<int>(now->tm_year) + 1900; 36 int month = now->tm_mon + 1; 37 int day = now->tm_mday; 38 int hour = nowMs / (1000LL * 60 * 60) % 24; 39 int minute = nowMs / (1000LL * 60) % 60; 40 int second = nowMs / (1000LL) % 60; 41 int milliseconds = nowMs % 1000; 42 int longWidth = 4; 43 int middleWidth = 3; 44 int minWidth = 2; 45 char fill = '0'; 46 algnlogger << std::setw(longWidth) << std::setfill(fill) << year 47 << "/" << std::setw(minWidth) << std::setfill(fill) << month 48 << "/" << std::setw(minWidth) << std::setfill(fill) << day 49 << " " << std::setw(minWidth) << std::setfill(fill) << hour 50 << ":" << std::setw(minWidth) << std::setfill(fill) << minute 51 << ":" << std::setw(minWidth) << std::setfill(fill) << second 52 << "." << std::setw(middleWidth) << std::setfill(fill) << milliseconds; 53 } 54 55 if (algnlogger.GetLevel() != Logger::LOG_LEVEL::DEBUG) { 56 Logger::OutputByStdout(algnlogger, phase); 57 } 58 } 59 } // namespace TextEngine 60 } // namespace Rosen 61 } // namespace OHOS 62