Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
3e00496d
Commit
3e00496d
authored
Oct 17, 2008
by
Alvaro Herrera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor some duplicate code to set up formatted_log_time and
formatted_start_time.
parent
e4fb8ff0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
72 deletions
+62
-72
src/backend/utils/error/elog.c
src/backend/utils/error/elog.c
+62
-72
No files found.
src/backend/utils/error/elog.c
View file @
3e00496d
...
...
@@ -42,7 +42,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.20
7 2008/10/09 17:24:05
alvherre Exp $
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.20
8 2008/10/17 22:56:16
alvherre Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -146,6 +146,8 @@ static void append_with_tabs(StringInfo buf, const char *str);
static
bool
is_log_level_output
(
int
elevel
,
int
log_min_level
);
static
void
write_pipe_chunks
(
char
*
data
,
int
len
,
int
dest
);
static
void
write_csvlog
(
ErrorData
*
edata
);
static
void
setup_formatted_log_time
(
void
);
static
void
setup_formatted_start_time
(
void
);
/*
* errstart --- begin an error-reporting cycle
...
...
@@ -1481,6 +1483,60 @@ write_eventlog(int level, const char *line)
}
#endif
/* WIN32 */
/*
* setup formatted_log_time, for consistent times between CSV and regular logs
*/
static
void
setup_formatted_log_time
(
void
)
{
struct
timeval
tv
;
pg_time_t
stamp_time
;
pg_tz
*
tz
;
char
msbuf
[
8
];
gettimeofday
(
&
tv
,
NULL
);
stamp_time
=
(
pg_time_t
)
tv
.
tv_sec
;
/*
* Normally we print log timestamps in log_timezone, but during startup we
* could get here before that's set. If so, fall back to gmt_timezone
* (which guc.c ensures is set up before Log_line_prefix can become
* nonempty).
*/
tz
=
log_timezone
?
log_timezone
:
gmt_timezone
;
pg_strftime
(
formatted_log_time
,
FORMATTED_TS_LEN
,
/* leave room for milliseconds... */
"%Y-%m-%d %H:%M:%S %Z"
,
pg_localtime
(
&
stamp_time
,
tz
));
/* 'paste' milliseconds into place... */
sprintf
(
msbuf
,
".%03d"
,
(
int
)
(
tv
.
tv_usec
/
1000
));
strncpy
(
formatted_log_time
+
19
,
msbuf
,
4
);
}
/*
* setup formatted_start_time
*/
static
void
setup_formatted_start_time
(
void
)
{
pg_time_t
stamp_time
=
(
pg_time_t
)
MyStartTime
;
pg_tz
*
tz
;
/*
* Normally we print log timestamps in log_timezone, but during startup we
* could get here before that's set. If so, fall back to gmt_timezone
* (which guc.c ensures is set up before Log_line_prefix can become
* nonempty).
*/
tz
=
log_timezone
?
log_timezone
:
gmt_timezone
;
pg_strftime
(
formatted_start_time
,
FORMATTED_TS_LEN
,
"%Y-%m-%d %H:%M:%S %Z"
,
pg_localtime
(
&
stamp_time
,
tz
));
}
/*
* Format tag info for log lines; append to the provided buffer.
*/
...
...
@@ -1561,34 +1617,8 @@ log_line_prefix(StringInfo buf)
appendStringInfo
(
buf
,
"%ld"
,
log_line_number
);
break
;
case
'm'
:
{
struct
timeval
tv
;
pg_time_t
stamp_time
;
pg_tz
*
tz
;
char
msbuf
[
8
];
gettimeofday
(
&
tv
,
NULL
);
stamp_time
=
(
pg_time_t
)
tv
.
tv_sec
;
/*
* Normally we print log timestamps in log_timezone, but
* during startup we could get here before that's set. If
* so, fall back to gmt_timezone (which guc.c ensures is
* set up before Log_line_prefix can become nonempty).
*/
tz
=
log_timezone
?
log_timezone
:
gmt_timezone
;
pg_strftime
(
formatted_log_time
,
FORMATTED_TS_LEN
,
/* leave room for milliseconds... */
"%Y-%m-%d %H:%M:%S %Z"
,
pg_localtime
(
&
stamp_time
,
tz
));
/* 'paste' milliseconds into place... */
sprintf
(
msbuf
,
".%03d"
,
(
int
)
(
tv
.
tv_usec
/
1000
));
strncpy
(
formatted_log_time
+
19
,
msbuf
,
4
);
appendStringInfoString
(
buf
,
formatted_log_time
);
}
setup_formatted_log_time
();
appendStringInfoString
(
buf
,
formatted_log_time
);
break
;
case
't'
:
{
...
...
@@ -1606,16 +1636,7 @@ log_line_prefix(StringInfo buf)
break
;
case
's'
:
if
(
formatted_start_time
[
0
]
==
'\0'
)
{
pg_time_t
stamp_time
=
(
pg_time_t
)
MyStartTime
;
pg_tz
*
tz
;
tz
=
log_timezone
?
log_timezone
:
gmt_timezone
;
pg_strftime
(
formatted_start_time
,
FORMATTED_TS_LEN
,
"%Y-%m-%d %H:%M:%S %Z"
,
pg_localtime
(
&
stamp_time
,
tz
));
}
setup_formatted_start_time
();
appendStringInfoString
(
buf
,
formatted_start_time
);
break
;
case
'i'
:
...
...
@@ -1731,32 +1752,8 @@ write_csvlog(ErrorData *edata)
* to put same timestamp in both syslog and csvlog messages.
*/
if
(
formatted_log_time
[
0
]
==
'\0'
)
{
struct
timeval
tv
;
pg_time_t
stamp_time
;
pg_tz
*
tz
;
char
msbuf
[
8
];
gettimeofday
(
&
tv
,
NULL
);
stamp_time
=
(
pg_time_t
)
tv
.
tv_sec
;
/*
* Normally we print log timestamps in log_timezone, but during
* startup we could get here before that's set. If so, fall back to
* gmt_timezone (which guc.c ensures is set up before Log_line_prefix
* can become nonempty).
*/
tz
=
log_timezone
?
log_timezone
:
gmt_timezone
;
pg_strftime
(
formatted_log_time
,
FORMATTED_TS_LEN
,
/* leave room for milliseconds... */
"%Y-%m-%d %H:%M:%S %Z"
,
pg_localtime
(
&
stamp_time
,
tz
));
setup_formatted_log_time
();
/* 'paste' milliseconds into place... */
sprintf
(
msbuf
,
".%03d"
,
(
int
)
(
tv
.
tv_usec
/
1000
));
strncpy
(
formatted_log_time
+
19
,
msbuf
,
4
);
}
appendStringInfoString
(
&
buf
,
formatted_log_time
);
appendStringInfoChar
(
&
buf
,
','
);
...
...
@@ -1813,14 +1810,7 @@ write_csvlog(ErrorData *edata)
/* session start timestamp */
if
(
formatted_start_time
[
0
]
==
'\0'
)
{
pg_time_t
stamp_time
=
(
pg_time_t
)
MyStartTime
;
pg_tz
*
tz
=
log_timezone
?
log_timezone
:
gmt_timezone
;
pg_strftime
(
formatted_start_time
,
FORMATTED_TS_LEN
,
"%Y-%m-%d %H:%M:%S %Z"
,
pg_localtime
(
&
stamp_time
,
tz
));
}
setup_formatted_start_time
();
appendStringInfoString
(
&
buf
,
formatted_start_time
);
appendStringInfoChar
(
&
buf
,
','
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment