I've seen the use of /dev/console in several scripts for Mac OSX but I'm not sure how it's being used. I checked Console.app and didn't see the results of my test command:

echo test > /dev/console

being printed out there, so where does it go to, or how would you use it?

| improve this question | | | | |
  • @Qosmo. This question is 100% valid for Super User and there is no need or reason to migrate it. – BinaryMisfit Feb 15 '11 at 15:57
  • Being valid doesn't imply it would be better served there? Why was it created? Anyway it's just a suggestion... – Brave Newbie Feb 15 '11 at 17:33

The /dev/console device is not especially related to the Console application.

In Mac OS X 10.6, the Console application has two kinds of data sources that it reads: normal log files (e.g. the files in /var/log/), and messages logged through the (Apple extended) syslog facility.

If you have a log file that you want to monitor, you can use the File > Open… menu item (⌘O) to view the file in Console.
Note: The only way to remove a file from Console’s list of files seems to be to use its File > Move to Trash menu item (⌘⌫); be prepared to pull the file out of the Trash if you just want to stop watching it in Console.

You can use the syslog command-line program to send messages to the syslog facility.

syslog -s Your message goes here. \(quote special chars for the shell'!)'

However, under the default configuration, this message will never show up in any of the Console views because it’s “level” is too low to be important. This initial filtering is due by syslogd. It is configured by the asl.conf and syslog.conf files. The default configuration does not store most messages if their Level is too low (and syslog -s defaults to the lowest level). Console can only show message that have been stored by syslogd.

You can change the value of the Level field by using the -l option:

syslog -s -l notice This message should show up in \"All Messages\" \
  with a Facility of syslog.

The notice level is the (default) lowest level for which syslogd will store most messages.

A message generated like this will show up in Console’s built-in “All Messsages” database search
(the file All Messages.aslquery in /Applications/Utilities/Console.app/Contents/Resources/ASLQueries/ technically limits it to message where the Facility field “contains” the empty string, but this condition is trivially satisfied by any Facility value).

If you want your message to appear in Console’s built-in “Console Messages” database search, then you must be a bit more specific. It only shows (stored) messages that have a Facility field that equals com.apple.console (see the file Console Messages.aslquery in /Applications/Utilities/Console.app/Contents/Resources/ASLQueries/). You can generate such messages with syslog by the -k option to set the Facility field.

syslog -s -k Facility com.apple.console \
          -k Level notice \
          -k Message 'This will show up in "Console Messages"'

When using -k, all the options and the message itself must be specified with sets of -k key value arguments (we can not use -l to set the level). This means that we have to put the message a single argument so it can be the value of the Message field.

| improve this answer | | | | |
  • So what is the "logger" command used for? Is it part of syslog? – cwd Mar 29 '11 at 12:56
  • @cwd: It also uses the syslog facility. Apple’s syslog has two main interfaces: syslog(3), and asl(3). The former is fairly standard on most Unix-y systems these days; logger uses it. The latter is an Apple-specific extension; the syslog command uses it. Console sees messages from both, but the “Console Messages” search needs an Apple-extended Facility value (which logger can not make). – Chris Johnsen Mar 29 '11 at 19:55

i use:

logger Hello World

always works for me. dumps "hello world" to syslog, which should show up in console.app

| improve this answer | | | | |

I'm not positive, but it may be the device called when >console is entered in the username field of the login window. When you enter the above it dumps you the CLI.

| improve this answer | | | | |

You can write to a file of your choosing that you could then view in the Console application.

If you want logging for user level use:

echo "test" > /Users/$USER/Library/Logs/your_script.log

or for something that is loaded for all users:

echo "test" > /Library/Logs/your_script.log
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.