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) {
92
92
GIOStatus write_status ;
93
93
GError * error = NULL ;
94
94
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
+
96
104
while (TRUE) {
97
105
if (_use_locks ) {
98
106
int res = flock (g_io_channel_unix_get_fd (_out_channel ), LOCK_EX );
@@ -101,18 +109,6 @@ gboolean write_output_channel(GString *buffer) {
101
109
}
102
110
}
103
111
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
-
116
112
write_status = g_io_channel_write_chars (_out_channel , buffer -> str ,
117
113
buffer -> len , & written , & error );
118
114
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) {
116
116
return g_strdup_printf ("%s%s" , str , outstr );
117
117
}
118
118
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
-
139
119
/**
140
120
* Compute absolute file path from directory path and file name
141
121
*
Original file line number Diff line number Diff line change 7
7
glong get_file_size (const gchar * file_path );
8
8
glong get_current_timestamp ();
9
9
gchar * compute_strftime_suffix (const gchar * str , const gchar * strftime_suffix );
10
- gchar * compute_timestamp_prefix (const gchar * strftime_prefix );
11
10
gchar * get_unique_hexa_identifier ();
12
11
glong get_file_inode (const gchar * file_path );
13
12
glong get_fd_inode (int fd );
You can’t perform that action at this time.
0 commit comments