mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 12:38:40 +00:00
fix
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
#if defined(USE_HOST)
|
||||
#include "logger.h"
|
||||
#ifdef USE_TIME_TIMEZONE
|
||||
#include "esphome/components/time/posix_tz.h"
|
||||
#endif
|
||||
|
||||
namespace esphome::logger {
|
||||
|
||||
@@ -14,11 +11,7 @@ void HOT Logger::write_msg_(const char *msg, size_t len) {
|
||||
time_t rawtime;
|
||||
::time(&rawtime);
|
||||
struct tm timeinfo;
|
||||
#ifdef USE_TIME_TIMEZONE
|
||||
time::epoch_to_local_tm(rawtime, time::get_global_tz(), &timeinfo);
|
||||
#else
|
||||
localtime_r(&rawtime, &timeinfo); // Thread-safe version
|
||||
#endif
|
||||
localtime_r(&rawtime, &timeinfo); // TZ env var set by time component
|
||||
size_t pos = strftime(buffer, TIMESTAMP_LEN + 1, "[%H:%M:%S]", &timeinfo);
|
||||
|
||||
// Copy message (with newline already included by caller)
|
||||
|
||||
@@ -104,6 +104,12 @@ void RealTimeClock::apply_timezone_(const char *tz) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef USE_HOST
|
||||
// On host platform, also set TZ environment variable for libc compatibility
|
||||
setenv("TZ", tz, 1);
|
||||
tzset();
|
||||
#endif
|
||||
|
||||
// Parse the POSIX TZ string using our custom parser
|
||||
if (!parse_posix_tz(tz, parsed)) {
|
||||
ESP_LOGW(TAG, "Failed to parse timezone: %s", tz);
|
||||
|
||||
Reference in New Issue
Block a user