JNIEXPORT void JNICALL Java_org_zeromq_czmq_Zsys__1_1setLogident (JNIEnv *env, jclass c, jstring value) { char *value_ = (char *) (*env)->GetStringUTFChars (env, value, NULL); zsys_set_logident (value_); (*env)->ReleaseStringUTFChars (env, value, value_); }
/// // Set log identity, which is a string that prefixes all log messages sent // by this process. The log identity defaults to the environment variable // ZSYS_LOGIDENT, if that is set. void QmlZsysAttached::setLogident (const QString &value) { zsys_set_logident (value.toUtf8().data()); };
void * zsys_init (void) { if (s_initialized) { assert (s_process_ctx); return s_process_ctx; } // Pull process defaults from environment if (getenv ("ZSYS_IO_THREADS")) s_io_threads = atoi (getenv ("ZSYS_IO_THREADS")); if (getenv ("ZSYS_MAX_SOCKETS")) s_max_sockets = atoi (getenv ("ZSYS_MAX_SOCKETS")); if (getenv ("ZSYS_LINGER")) s_linger = atoi (getenv ("ZSYS_LINGER")); if (getenv ("ZSYS_SNDHWM")) s_sndhwm = atoi (getenv ("ZSYS_SNDHWM")); if (getenv ("ZSYS_RCVHWM")) s_rcvhwm = atoi (getenv ("ZSYS_RCVHWM")); if (getenv ("ZSYS_PIPEHWM")) s_pipehwm = atoi (getenv ("ZSYS_PIPEHWM")); if (getenv ("ZSYS_IPV6")) s_ipv6 = atoi (getenv ("ZSYS_IPV6")); if (getenv ("ZSYS_LOGSTREAM")) { if (streq (getenv ("ZSYS_LOGSTREAM"), "stdout")) s_logstream = stdout; else if (streq (getenv ("ZSYS_LOGSTREAM"), "stderr")) s_logstream = stderr; } else s_logstream = stdout; if (getenv ("ZSYS_LOGSYSTEM")) { if (streq (getenv ("ZSYS_LOGSYSTEM"), "true")) s_logsystem = true; else if (streq (getenv ("ZSYS_LOGSYSTEM"), "false")) s_logsystem = false; } // Catch SIGINT and SIGTERM unless ZSYS_SIGHANDLER=false if ( getenv ("ZSYS_SIGHANDLER") == NULL || strneq (getenv ("ZSYS_SIGHANDLER"), "false")) zsys_catch_interrupts (); ZMUTEX_INIT (s_mutex); s_sockref_list = zlist_new (); if (!s_sockref_list) { zsys_shutdown (); return NULL; } srandom ((unsigned) time (NULL)); atexit (zsys_shutdown); assert (!s_process_ctx); // We use zmq_init/zmq_term to keep compatibility back to ZMQ v2 s_process_ctx = zmq_init ((int) s_io_threads); #if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (3, 2, 0)) // TODO: this causes TravisCI to break; libzmq does not return a // valid socket on zmq_socket(), after this... zmq_ctx_set (s_process_ctx, ZMQ_MAX_SOCKETS, s_max_sockets); #endif s_initialized = true; // The following functions call zsys_init(), so they MUST be called after // s_initialized is set in order to avoid an infinite recursion if (getenv ("ZSYS_INTERFACE")) zsys_set_interface (getenv ("ZSYS_INTERFACE")); if (getenv ("ZSYS_LOGIDENT")) zsys_set_logident (getenv ("ZSYS_LOGIDENT")); if (getenv ("ZSYS_LOGSENDER")) zsys_set_logsender (getenv ("ZSYS_LOGSENDER")); return s_process_ctx; }
void zsys_test (bool verbose) { printf (" * zsys: "); if (verbose) printf ("\n"); // @selftest zsys_catch_interrupts (); // Check capabilities without using the return value int rc = zsys_has_curve (); if (verbose) { char *hostname = zsys_hostname (); zsys_info ("host name is %s", hostname); free (hostname); zsys_info ("system limit is %zd ZeroMQ sockets", zsys_socket_limit ()); } zsys_set_io_threads (1); zsys_set_max_sockets (0); zsys_set_linger (0); zsys_set_sndhwm (1000); zsys_set_rcvhwm (1000); zsys_set_pipehwm (2500); assert (zsys_pipehwm () == 2500); zsys_set_ipv6 (0); rc = zsys_file_delete ("nosuchfile"); assert (rc == -1); bool rc_bool = zsys_file_exists ("nosuchfile"); assert (rc_bool != true); rc = (int) zsys_file_size ("nosuchfile"); assert (rc == -1); time_t when = zsys_file_modified ("."); assert (when > 0); mode_t mode = zsys_file_mode ("."); assert (S_ISDIR (mode)); assert (mode & S_IRUSR); assert (mode & S_IWUSR); zsys_file_mode_private (); rc = zsys_dir_create ("%s/%s", ".", ".testsys/subdir"); assert (rc == 0); when = zsys_file_modified ("./.testsys/subdir"); assert (when > 0); assert (!zsys_file_stable ("./.testsys/subdir")); rc = zsys_dir_delete ("%s/%s", ".", ".testsys/subdir"); assert (rc == 0); rc = zsys_dir_delete ("%s/%s", ".", ".testsys"); assert (rc == 0); zsys_file_mode_default (); int major, minor, patch; zsys_version (&major, &minor, &patch); assert (major == CZMQ_VERSION_MAJOR); assert (minor == CZMQ_VERSION_MINOR); assert (patch == CZMQ_VERSION_PATCH); char *string = zsys_sprintf ("%s %02x", "Hello", 16); assert (streq (string, "Hello 10")); free (string); char *str64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,."; int num10 = 1234567890; string = zsys_sprintf ("%s%s%s%s%d", str64, str64, str64, str64, num10); assert (strlen (string) == (4 * 64 + 10)); free (string); // Test logging system zsys_set_logident ("czmq_selftest"); zsys_set_logsender ("inproc://logging"); void *logger = zsys_socket (ZMQ_SUB, NULL, 0); assert (logger); rc = zsocket_connect (logger, "inproc://logging"); assert (rc == 0); rc = zmq_setsockopt (logger, ZMQ_SUBSCRIBE, "", 0); assert (rc == 0); if (verbose) { zsys_error ("This is an %s message", "error"); zsys_warning ("This is a %s message", "warning"); zsys_notice ("This is a %s message", "notice"); zsys_info ("This is a %s message", "info"); zsys_debug ("This is a %s message", "debug"); zsys_set_logident ("hello, world"); zsys_info ("This is a %s message", "info"); zsys_debug ("This is a %s message", "debug"); // Check that logsender functionality is working char *received = zstr_recv (logger); assert (received); zstr_free (&received); } zsys_close (logger, NULL, 0); // @end printf ("OK\n"); }
/// // Set log identity, which is a string that prefixes all log messages sent // by this process. The log identity defaults to the environment variable // ZSYS_LOGIDENT, if that is set. void QZsys::setLogident (const QString &value) { zsys_set_logident (value.toUtf8().data()); }