Linux::Dmesg

Download Source

Linux::Dmesg - Perl extension for access to klogctl() functions. This allows reading from the kernel console printk buffer as used by the dmesg(8) command.

SYNOPSIS

use Linux::Dmesg;

my $dmesg = Linux::Dmesg::dmesg;

DESCRIPTION

The Linux::Dmesg module allows direct access to the functions provided by the klogctl(2) interface. The most common usage is to read the kernel printk console buffer. The root user also has access to other functions to clear the buffer, enable/disable the logging and set the logging levels.

FUNCTIONS

The following functions are exported by the Linux::Dmesg module. None of these functions are exported by default.

  • dmesg($level)

Returns the current kernel message bufffer ring. The log level at the start of each line is removed. An optional level can be specified and only messages at this level or lower will be returned. See LEVELs below.

  • read_buffer

Returns the current kernel message buffer ring without removing the log level at the start of each line.

  • read_clear_buffer

Returns and clears the current kernel message buffer ring without removing the log level at the start of each line. Requires root permission.

  • clear_buffer

Clears the current kernel message buffer ring. Requires root permission.

  • disable_printk

Disables printk to the console. Requires root permission.

  • enable_printk

Enables printk to the console. Requires root permission.

  • printk_level(l$evel)

Set the console printk level. See LEVELS below. Requires root permission.

  • unread_count

Returns the number of unread characters in the buffer.

  • buffer_size

Returns the size of the buffer.

EXPORT

None by default.

LEVELS

The following log levels are defined and exported as constants:

  • KERN_EMERG 0 The system is unusable
  • KERN_ALERT 1 Action must be taken immediately
  • KERN_CRIT 2 Critical conditions
  • KERN_ERR 3 Error conditions
  • KERN_WARNING 4 Warning conditions
  • KERN_NOTICE 5 Normal but significant condition
  • KERN_INFO 6 Informational
  • KERN_DEBUG 7 Debug-level messages

INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

SEE ALSO

syslog(2), klogctl(2), dmesg(8)

AUTHOR

Simon Evans, si@si.org

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Simon Evans

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language itself.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.