Apple Bug Friday! 72

2008-01-25 19:45:38 UTC

This bug is ASL provides no way to not escape messages written to a file. It was filed on 2008-01-18 at 18:44 PST.


Summary:

ASL escapes every message it writes to a file, providing no option to not escape messages sent to the file.

Steps to Reproduce:

  1. Create a client connection with asl_open.
  2. Add one or more files to the connection with asl_add_log_file.
  3. ???
  4. Log messages using asl_log, asl_vlog, or asl_send.

Expected Results:

The message is written to the log.

Actual Results:

The message is escaped using strvis(3), then written to the log.

Regression:

None. Tiger’s ASL worked like this, too.

Notes:

I understand that the escaping is intended to be a feature, so that logs can be loaded and parsed. However, we don’t always want that. In particular, when I log to stderr, I sometimes create log messages that span multiple lines on purpose. Also, NSCFDictionary and NSCFArray often return descriptions with one pair or one element per line. For example:

(
	"foo
	bar",
	"bar
	baz",
	"baz
	qux",
)

becomes:

(\n\t"foo\n\tbar",\n\t"bar\n\tbaz",\n\t"baz\n\tqux",\n)

You can see how this is harder to read. It’s now much harder to tell where each string begins and ends. This makes reading ASL messages in the Xcode Run Log almost useless.

So, I’m asking for a function that would enable or disable this escaping on a per-file basis. Something like:

int asl_set_escaping_enabled(aslclient asl, int fd, bool enable);

The default would be to have it enabled, except that if you pass ASL_OPT_STDERR to asl_open, asl_open would call asl_set_escaping_enabled(result, STDERR_FILENO, false) for you.

A more general solution would be some sort of message transformation system. The API would look like:

int asl_add_transform_function(aslclient asl, asltransformfunc xform, int priority);
int asl_remove_transform_function(aslclient asl, asltransformfunc xform);
typedef void (*asltransformfunc)(aslmsg msg);
void asl_transform_strvis(aslmsg msg);

Thus, you could disable the escaping by calling:

asl_remove_transform_function(my_asl, asl_transform_strvis);

I included the priority argument so that clients could specify the order of their custom transformations.

In keeping with the existing behavior, asl_add_log_file would add the strvis transformation automatically (with, I imagine, a priority of 0). And, as above, stderr when added with ASL_OPT_STDERR would not have this transformation added to it.

Leave a Reply

Do not delete the second sentence.