This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sdk:log-to-syslog [2016/09/28 12:09] – [The Script] fachet | sdk:log-to-syslog [2016/10/05 15:36] (current) – [The Script] nicer line break without value break juraschek | ||
|---|---|---|---|
| Line 14: | Line 14: | ||
| <code c > | <code c > | ||
| - | example: | + | Example: |
| Single Log with 5 Parameter: | Single Log with 5 Parameter: | ||
| Line 39: | Line 39: | ||
| ===== Check if the script is running ===== | ===== Check if the script is running ===== | ||
| - | In the Systemlog under System-> | + | In the Systemlog under [[http:// |
| you will find the log output: | you will find the log output: | ||
| Line 61: | Line 61: | ||
| | | ||
| | | ||
| - | <code c stus-to-syslog.are> | + | <code c status-to-syslog.are> |
| - | /* DESC: A Script that can be used for a longtime logging of a NetModule Wireless Router. | + | /* DESC: A Script that can be used for a longtime logging of a NetModule Wireless Router. |
| - | * The upper part of the script is the logger template. The lower part is the real programm, where you describe the settings and workflow. | + | |
| - | * Copyright (C) 2016 NetModule AG, Switzerland | + | |
| - | */ | + | |
| - | + | | |
| - | template logger | + | |
| - | { | + | |
| - | + | { | |
| - | # give the constructor the array of fields to log | + | |
| - | void logger(array logfields) { | + | # give the constructor the array of fields to log |
| - | this.fields = logfields; | + | void logger(array logfields) { |
| - | } | + | this.fields = logfields; |
| - | + | ||
| - | int logNow(){ | + | |
| - | //get current status output | + | |
| - | sections = mkarray(" | + | |
| - | status = mkstruct(); | + | |
| - | for(i = 0; i < length(sections); | + | |
| - | status=struct_merge(status, | + | |
| } | } | ||
| + | |||
| + | int logNow(){ | ||
| + | MAX_LINE_LEN=180; | ||
| + | //get current status output | ||
| + | sections = mkarray(" | ||
| + | status = mkstruct(); | ||
| + | for(i = 0; i < length(sections); | ||
| + | status=struct_merge(status, | ||
| + | } | ||
| + | |||
| + | line = ""; | ||
| | | ||
| - | line = ""; | + | |
| - | | + | if(strlen(this.fields[i]) > 0 ) { |
| - | if(strlen(this.fields[i]) > 0 ) { | + | value = struct_get(status, |
| - | value = struct_get(status, | + | if(strlen(value) == 0) { |
| - | if(strlen(value) == 0) { | + | value = sprintf(" |
| - | value = sprintf(" | + | } |
| + | |||
| + | if(strlen(this.fields[i+1]) > 0 ) { | ||
| + | nextvalue = struct_get(status, | ||
| + | if(strlen(nextvalue) == 0) { | ||
| + | nextvalue = sprintf(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | //line = sprintf(' | ||
| + | line = sprintf(" | ||
| + | if (strlen(line)+strlen(sprintf(" | ||
| + | nb_syslog(line); | ||
| + | line=""; | ||
| + | } | ||
| + | | ||
| } | } | ||
| - | //line = sprintf(' | ||
| - | line = sprintf(" | ||
| } | } | ||
| + | if (strlen(line) > 0) nb_syslog(line); | ||
| + | |||
| + | return 0; | ||
| } | } | ||
| - | nb_syslog("%s", line); | + | |
| - | | + | |
| + | } // of template logger | ||
| + | |||
| + | if (argc < 3){ | ||
| + | printf("usage: status_to_syslog.are [single|< | ||
| + | | ||
| } | } | ||
| + | |||
| + | if (argv[1] == " | ||
| + | mode = 0; | ||
| + | else | ||
| + | mode = (int) argv[1]; | ||
| + | |||
| + | elements = mkarray(); | ||
| + | for (i = 2; i <= argc; i++) { | ||
| + | elements = array_merge(elements, | ||
| + | } | ||
| + | l = new logger(elements); | ||
| + | |||
| + | do { | ||
| + | l.logNow(); | ||
| + | sleep(mode); | ||
| + | } while(mode); | ||
| + | exit(0); | ||
| - | } // of template logger | ||
| - | if (argc < 1){ | ||
| - | printf(" | ||
| - | exit(1); | ||
| - | } | ||
| - | mode = argv[1]; | ||
| - | elements = mkarray(); | ||
| - | for (i = 2; i <= argc; i++) { | ||
| - | elements = array_merge(elements, | ||
| - | } | ||
| - | |||
| - | do { | ||
| - | l = new logger(elements); | ||
| - | l.logNow(); | ||
| - | sleep((int)mode); | ||
| - | } while (mode != " | ||
| - | exit(0); | ||
| </ | </ | ||