File tree Expand file tree Collapse file tree 3 files changed +9
-34
lines changed
Expand file tree Collapse file tree 3 files changed +9
-34
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,15 @@ gboolean write_output_channel(GString *buffer) {
9292 GIOStatus write_status ;
9393 GError * error = NULL ;
9494 gsize written ;
95- gsize written_timestamp = 0 ;
95+
96+ if ( _timestamp_prefix != NULL ) {
97+ GDateTime * dt = g_date_time_new_now_local ();
98+ gchar * prefix = g_date_time_format (dt , _timestamp_prefix );
99+ g_string_prepend (buffer , prefix );
100+ g_free (prefix );
101+ g_date_time_unref (dt );
102+ }
103+
96104 while (TRUE) {
97105 if (_use_locks ) {
98106 int res = flock (g_io_channel_unix_get_fd (_out_channel ), LOCK_EX );
@@ -101,18 +109,6 @@ gboolean write_output_channel(GString *buffer) {
101109 }
102110 }
103111
104- if ( _timestamp_prefix != NULL && written_timestamp == 0 ) {
105- gchar * timestamp = compute_timestamp_prefix (_timestamp_prefix );
106- if ( timestamp != NULL ) {
107- write_status = g_io_channel_write_chars (_out_channel , timestamp ,
108- strlen (timestamp ), & written_timestamp , & error );
109- g_free (timestamp );
110- if (write_status == G_IO_STATUS_AGAIN ) {
111- continue ;
112- }
113- }
114- }
115-
116112 write_status = g_io_channel_write_chars (_out_channel , buffer -> str ,
117113 buffer -> len , & written , & error );
118114 if (_use_locks ) {
Original file line number Diff line number Diff line change @@ -116,26 +116,6 @@ gchar *compute_strftime_suffix(const gchar *str, const gchar *strftime_suffix) {
116116 return g_strdup_printf ("%s%s" , str , outstr );
117117}
118118
119- /**
120- * Format current timestamp prefix to prepend to a log line.
121- *
122- * @param strftime_prefix format with strftime placeholders to expand with current time.
123- * @return newly allocated string (free it with g_free) with the current timestamp prefix.
124- */
125- gchar * compute_timestamp_prefix (const gchar * strftime_prefix ) {
126- time_t t ;
127- struct tm * tmp ;
128- t = time (NULL );
129- tmp = localtime (& t );
130- g_assert (tmp != NULL );
131- char outstr [100 ];
132- if (strftime (outstr , sizeof (outstr ), strftime_prefix , tmp ) == 0 ) {
133- g_critical ("problem with strftime on %s" , strftime_prefix );
134- return NULL ;
135- }
136- return g_strdup (outstr );
137- }
138-
139119/**
140120 * Compute absolute file path from directory path and file name
141121 *
Original file line number Diff line number Diff line change 77glong get_file_size (const gchar * file_path );
88glong get_current_timestamp ();
99gchar * compute_strftime_suffix (const gchar * str , const gchar * strftime_suffix );
10- gchar * compute_timestamp_prefix (const gchar * strftime_prefix );
1110gchar * get_unique_hexa_identifier ();
1211glong get_file_inode (const gchar * file_path );
1312glong get_fd_inode (int fd );
You can’t perform that action at this time.
0 commit comments