'log level'에 해당하는 글 2건

출처 :  http://tuxthink.blogspot.kr/2012/07/printk-and-console-log-level.html


printk and console log level.

printk is used in kernel programming to print messages into the kernel logs. 

The syntax of printk is 

 

The log levels decide the importance of the message being printed, kernel defines 8 log levels in the file printk.h 

 

We can see each log level corresponds to a number and the lower the number higher the importance of the message. 
The levels are useful in deciding what should be displayed to the user on the console and what should not be. 

Every console has log level called as the the console log level and any message with a log level number lesser than the console log level gets displayed on the console, and other messages which have a log level number higher or equal to the console log level are logged in the kernel log which can be looked into using the command "dmesg". 

The console loglevel can be found by looking into the file /proc/sys/kernel/printk 

 

The first number in the output is the console log level, the second is the default log level, third is the minimum log level and fourth is the maximum log level. 

Log level 4 corresponds to KERN_WARNING. Thus all the messages with log levels 3,2,1 and 0 will get displayed on the screen as well as logged and the messages with log level 4,5,6,7 only get logged and can be viewed using "dmesg". 

The console log level can be changed by writing into the proc entry 

 

Now the console log level is set to 6, which is KERN_INFO. 

We can test logging by using the following module 

hello.c: 

 

The printk called in the init function uses KERN_WARNING which is log level and lesser than 6 which is the console log level and hence should be seen on the screen. 

The printk used in the exit function is KERN_INFO which is log level 6,same as the console log level, and hence should not be visible on the screen. 

Note: We can test the operation of the code only by logging into a text mode as none of the messages are displayed on a terminal of GUI. 

Makefile: 

 

Compile and insert 

 

We can see the hello world being printed on the screen. 

 

The good bye world message gets logged but is not printed on the screen but can be see in the logs. 

Thus using printk and the console log levels we can control the kernel messages visible to the user. 


WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,



cat /proc/sys/kernel/printk

중요성을 기준으로 해서 로깅 메시지가 전송될 곳을 지정하는 숫자 값을 갖고 있다:

- Console Log Level: 이 값보다 높은 우선순위를 지닌 메시지들은 콘솔에 프린트된다. 
- Default Message Log Level: 우선순위가 없는 메시지들은 이 우선순위로 프린트된다. 
- Minimum Console Log Level: Console Log Level이 설정될 수 있는 최소(가장 높은 우선순위) 값. 
- Default Console Log Level: Console Log Level 용 기본 값.

기본 설정: 6 4 1 7

echo "0 4 1 7" > /proc/sys/kernel/printk 하면, 콘솔로 나타나는 모든 printk 메시지가 없어진다.

터미널로 띄우기 :
 /etc/syslog.conf 파일에서 #kern.* /dev/console 앞에 있는 #을 제거하고, /etc/rc.d/init.d/syslog restart 명령으로 syslog를 다시 시작합니다. 그런후 xterm -C 명령으로 콘솔 터미널을 띄우면 커널 메시지가 콘솔 터미널로 출력됩니다. 콘솔 터미널을 생성하지 않는 방법으로 cat /proc/kmsg를 해도 출력되는 메시지를 볼 수 있습니다


WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,