mirror of
https://github.com/php/php-src.git
synced 2025-08-18 23:18:56 +02:00
phpdbg_rlog for logging while in remote mode (only)
This commit is contained in:
parent
4fa2f01c4e
commit
df0091c445
4 changed files with 46 additions and 15 deletions
28
phpdbg.c
28
phpdbg.c
|
@ -600,8 +600,9 @@ int phpdbg_open_socket(const char *interface, short port) /* {{{ */
|
||||||
|
|
||||||
static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */
|
static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */
|
||||||
{
|
{
|
||||||
if ((*socket)[0]) {
|
if ((*socket)[0] >= 0) {
|
||||||
shutdown((*socket)[0], SHUT_RDWR);
|
shutdown(
|
||||||
|
(*socket)[0], SHUT_RDWR);
|
||||||
close((*socket)[0]);
|
close((*socket)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,8 +610,9 @@ static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {
|
||||||
fclose(streams[0]);
|
fclose(streams[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*socket)[1]) {
|
if ((*socket)[1] >= 0) {
|
||||||
shutdown((*socket)[1], SHUT_RDWR);
|
shutdown(
|
||||||
|
(*socket)[1], SHUT_RDWR);
|
||||||
close((*socket)[1]);
|
close((*socket)[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,13 +635,13 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock
|
||||||
|
|
||||||
if ((*listen)[0] < 0 || (*listen)[1] < 0) {
|
if ((*listen)[0] < 0 || (*listen)[1] < 0) {
|
||||||
if ((*listen)[0] < 0) {
|
if ((*listen)[0] < 0) {
|
||||||
fprintf(stderr,
|
phpdbg_rlog(stderr,
|
||||||
"Failed to start remote console (stdin) on port %d\n", port[0]);
|
"console failed to initialize (stdin) on %s:%d", address, port[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*listen)[1] < 0) {
|
if ((*listen)[1] < 0) {
|
||||||
fprintf(stderr,
|
phpdbg_rlog(stderr,
|
||||||
"Failed to open remote console (stdout) on port %d\n", port[1]);
|
"console failed to initialize (stdout) on %s:%d", address, port[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*listen)[0] >= 0) {
|
if ((*listen)[0] >= 0) {
|
||||||
|
@ -655,8 +657,8 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock
|
||||||
|
|
||||||
phpdbg_close_sockets(socket, streams);
|
phpdbg_close_sockets(socket, streams);
|
||||||
|
|
||||||
fprintf(stderr,
|
phpdbg_rlog(stderr,
|
||||||
"Remote console accepting (stdin/stdout) on ports %d/%d\n", port[0], port[1]);
|
"accepting connections on %s:%d/%d", address, port[0], port[1]);
|
||||||
{
|
{
|
||||||
struct sockaddr_in address;
|
struct sockaddr_in address;
|
||||||
socklen_t size = sizeof(address);
|
socklen_t size = sizeof(address);
|
||||||
|
@ -668,8 +670,7 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock
|
||||||
(*listen)[0], (struct sockaddr *) &address, &size);
|
(*listen)[0], (struct sockaddr *) &address, &size);
|
||||||
inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer));
|
inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer));
|
||||||
|
|
||||||
fprintf(stderr,
|
phpdbg_rlog(stderr, "connection (stdin) from %s", buffer);
|
||||||
"Remote console (stdin) connection from %s\n", buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -678,8 +679,7 @@ int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*sock
|
||||||
(*listen)[1], (struct sockaddr *) &address, &size);
|
(*listen)[1], (struct sockaddr *) &address, &size);
|
||||||
inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer));
|
inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer));
|
||||||
|
|
||||||
fprintf(stderr,
|
phpdbg_rlog(stderr, "connection (stdout) from %s", buffer);
|
||||||
"Remote console (stdout) connection from %s\n", buffer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -242,6 +242,35 @@ PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ..
|
||||||
return rc;
|
return rc;
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
|
|
||||||
|
PHPDBG_API int phpdbg_rlog(FILE *fp, const char *fmt, ...) { /* {{{ */
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
time_t now;
|
||||||
|
struct timeval tp;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
if (gettimeofday(&tp, NULL) == SUCCESS)
|
||||||
|
{
|
||||||
|
char friendly[100];
|
||||||
|
char *format = NULL, *buffer = NULL;
|
||||||
|
|
||||||
|
strftime(friendly, 100, "%a %b %d %T.%%04d %Y", localtime(&tp.tv_sec));
|
||||||
|
asprintf(
|
||||||
|
&buffer, friendly, tp.tv_usec/1000);
|
||||||
|
asprintf(
|
||||||
|
&format, "[%s]: %s\n", buffer, fmt);
|
||||||
|
rc = vfprintf(
|
||||||
|
fp, format, args);
|
||||||
|
|
||||||
|
free(format);
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC) /* {{{ */
|
PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC) /* {{{ */
|
||||||
{
|
{
|
||||||
const phpdbg_color_t *color = colors;
|
const phpdbg_color_t *color = colors;
|
||||||
|
|
|
@ -32,7 +32,7 @@ PHPDBG_API char *phpdbg_resolve_path(const char* TSRMLS_DC);
|
||||||
PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
|
PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error/notice/formatting helper
|
* Error/notice/formatting helpers
|
||||||
*/
|
*/
|
||||||
enum {
|
enum {
|
||||||
P_ERROR = 1,
|
P_ERROR = 1,
|
||||||
|
@ -48,6 +48,8 @@ PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUT
|
||||||
PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
|
PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
PHPDBG_API int phpdbg_rlog(FILE *stream, const char *fmt, ...);
|
||||||
|
|
||||||
#define phpdbg_error(fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
|
#define phpdbg_error(fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
|
||||||
#define phpdbg_notice(fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
|
#define phpdbg_notice(fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
|
||||||
#define phpdbg_writeln(fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
|
#define phpdbg_writeln(fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
|
||||||
|
|
BIN
tutorials/java/dist/phpdbg-ui.jar
vendored
BIN
tutorials/java/dist/phpdbg-ui.jar
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue