@@ -44,7 +44,18 @@ static const char *const colors[] = {
44
44
};
45
45
46
46
static uint32_t freq ;
47
- static uint32_t timestamp_div ;
47
+ static log_timestamp_t timestamp_div ;
48
+
49
+ #define SECONDS_IN_DAY 86400U
50
+
51
+ static uint32_t days_in_month [12 ] = {31 , 28 , 31 , 30 , 31 , 30 , 31 ,
52
+ 31 , 30 , 31 , 30 , 31 };
53
+
54
+ struct YMD_date {
55
+ uint32_t year ;
56
+ uint32_t month ;
57
+ uint32_t day ;
58
+ };
48
59
49
60
extern void log_output_msg_syst_process (const struct log_output * output ,
50
61
struct log_msg * msg , uint32_t flag );
@@ -169,19 +180,68 @@ void log_output_flush(const struct log_output *output)
169
180
output -> control_block -> offset = 0 ;
170
181
}
171
182
183
+ static inline bool is_leap_year (uint32_t year )
184
+ {
185
+ return (((year % 4 == 0 ) && (year % 100 != 0 )) || (year % 400 == 0 ));
186
+ }
187
+
188
+ static void __attribute__((unused )) get_YMD_from_seconds (uint64_t seconds ,
189
+ struct YMD_date * output_date )
190
+ {
191
+ uint64_t tmp ;
192
+ int i ;
193
+
194
+ output_date -> year = 1970 ;
195
+ output_date -> month = 1 ;
196
+ output_date -> day = 1 ;
197
+
198
+ /* compute the proper year */
199
+ while (1 ) {
200
+ tmp = (is_leap_year (output_date -> year )) ?
201
+ 366 * SECONDS_IN_DAY : 365 * SECONDS_IN_DAY ;
202
+ if (tmp > seconds ) {
203
+ break ;
204
+ }
205
+ seconds -= tmp ;
206
+ output_date -> year ++ ;
207
+ }
208
+ /* compute the proper month */
209
+ for (i = 0 ; i < sizeof (days_in_month ); i ++ ) {
210
+ tmp = ((i == 1 ) && is_leap_year (output_date -> year )) ?
211
+ (days_in_month [i ] + 1 ) * SECONDS_IN_DAY :
212
+ days_in_month [i ] * SECONDS_IN_DAY ;
213
+ if (tmp > seconds ) {
214
+ output_date -> month += i ;
215
+ break ;
216
+ }
217
+ seconds -= tmp ;
218
+ }
219
+
220
+ output_date -> day += seconds / SECONDS_IN_DAY ;
221
+ }
222
+
172
223
static int timestamp_print (const struct log_output * output ,
173
- uint32_t flags , uint32_t timestamp )
224
+ uint32_t flags , log_timestamp_t timestamp )
174
225
{
175
226
int length ;
176
227
bool format =
177
228
(flags & LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP ) |
178
- (flags & LOG_OUTPUT_FLAG_FORMAT_SYSLOG );
229
+ (flags & LOG_OUTPUT_FLAG_FORMAT_SYSLOG ) |
230
+ IS_ENABLED (CONFIG_LOG_OUTPUT_FORMAT_LINUX_TIMESTAMP );
179
231
180
232
181
233
if (!format ) {
234
+ #ifndef CONFIG_LOG_TIMESTAMP_64BIT
182
235
length = print_formatted (output , "[%08lu] " , timestamp );
236
+ #else
237
+ length = print_formatted (output , "[%016llu] " , timestamp );
238
+ #endif
183
239
} else if (freq != 0U ) {
240
+ #ifndef CONFIG_LOG_TIMESTAMP_64BIT
184
241
uint32_t total_seconds ;
242
+ #else
243
+ uint64_t total_seconds ;
244
+ #endif
185
245
uint32_t remainder ;
186
246
uint32_t seconds ;
187
247
uint32_t hours ;
@@ -216,14 +276,25 @@ static int timestamp_print(const struct log_output *output,
216
276
length = print_formatted (output , "%s.%06uZ " ,
217
277
time_str , ms * 1000U + us );
218
278
#else
279
+ struct YMD_date date ;
280
+
281
+ get_YMD_from_seconds (total_seconds , & date );
282
+ hours = hours % 24 ;
219
283
length = print_formatted (output ,
220
- "1970-01-01T%02u:%02u:%02u.%06uZ " ,
284
+ "%04u-%02u-%02uT%02u:%02u:%02u.%06uZ " ,
285
+ date .year , date .month , date .day ,
221
286
hours , mins , seconds , ms * 1000U + us );
222
287
#endif
223
288
} else {
224
- length = print_formatted (output ,
225
- "[%02u:%02u:%02u.%03u,%03u] " ,
226
- hours , mins , seconds , ms , us );
289
+ if (IS_ENABLED (CONFIG_LOG_OUTPUT_FORMAT_LINUX_TIMESTAMP )) {
290
+ length = print_formatted (output ,
291
+ "[%02u:%02u:%02u.%03u,%03u] " ,
292
+ hours , mins , seconds , ms , us );
293
+ } else {
294
+ length = print_formatted (output ,
295
+ "[%5ld.%06d] " ,
296
+ total_seconds , ms * 1000U + us );
297
+ }
227
298
}
228
299
} else {
229
300
length = 0 ;
@@ -493,7 +564,7 @@ static void raw_string_print(struct log_msg *msg,
493
564
}
494
565
495
566
static uint32_t prefix_print (const struct log_output * output ,
496
- uint32_t flags , bool func_on , uint32_t timestamp , uint8_t level ,
567
+ uint32_t flags , bool func_on , log_timestamp_t timestamp , uint8_t level ,
497
568
uint8_t domain_id , int16_t source_id )
498
569
{
499
570
uint32_t length = 0U ;
0 commit comments