Skip to content

Commit

Permalink
Merge pull request #17 from tpiekarski/feature/short-cutting-severity…
Browse files Browse the repository at this point in the history
…-levels

Merging, feature/short-cutting-severity-levels, resolves #4
  • Loading branch information
tpiekarski committed May 1, 2020
2 parents a353a30 + 3c724c2 commit 3dfc02d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 14 additions & 2 deletions pretty_printk.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@
#ifndef _LINUX_PRETTY_PRINTK_H
#define _LINUX_PRETTY_PRINTK_H

// todo: print a lot of things in (more or less) pretty way
#include <linux/kern_levels.h>
#include <linux/printk.h>

#define _LINUX_PP_MESSAGE "This is a demo module for pretty printk-ing"
// todo: Handle possible empty THIS_MODULE
#define _pp(severity, format, args...) \
printk(severity "%s:" #format "\n", THIS_MODULE->name, ##args)

#define pp_emerg(args...) _pp(KERN_EMERG, args)
#define pp_alert(args...) _pp(KERN_ALERT, args)
#define pp_crit(args...) _pp(KERN_CRIT, args)
#define pp_err(args...) _pp(KERN_ERR, args)
#define pp_warn(args...) _pp(KERN_WARNING, args)
#define pp_note(args...) _pp(KERN_NOTICE, args)
#define pp_info(args...) _pp(KERN_INFO, args)
#define pp_debug(args...) _pp(KERN_DEBUG, args)

#endif
13 changes: 11 additions & 2 deletions pretty_printk_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ MODULE_VERSION("0.1");

static int __init pretty_printk_demo_init(void)
{
// todo: implement some demo how to pretty printk-ing things
printk(KERN_INFO "%s: %s\n", THIS_MODULE->name, _LINUX_PP_MESSAGE);
// Internal macro
_pp(KERN_INFO, "Internal Pre-processing Macro...");

// External macros
pp_emerg("Emergency severity");
pp_crit("Critical severity");
pp_err("Error severity");
pp_warn("Warning severity");
pp_note("Notice severity");
pp_info("Information severity");
pp_debug("Debugging severity");

return 0;
}
Expand Down

0 comments on commit 3dfc02d

Please sign in to comment.