wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 1 | /* |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 2 | * (C) Copyright 2002-2007 |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 3 | * Detlev Zundel, DENX Software Engineering, dzu@denx.de. |
| 4 | * |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 5 | * Code used from linux/kernel/printk.c |
| 6 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 7 | * |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 25 | * |
| 26 | * Comments: |
| 27 | * |
| 28 | * After relocating the code, the environment variable "loglevel" is |
| 29 | * copied to console_loglevel. The functionality is similar to the |
| 30 | * handling in the Linux kernel, i.e. messages logged with a priority |
| 31 | * less than console_loglevel are also output to stdout. |
| 32 | * |
| 33 | * If you want messages with the default level (e.g. POST messages) to |
| 34 | * appear on stdout also, make sure the environment variable |
| 35 | * "loglevel" is set at boot time to a number higher than |
| 36 | * default_message_loglevel below. |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | /* |
| 40 | * Logbuffer handling routines |
| 41 | */ |
| 42 | |
| 43 | #include <common.h> |
| 44 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 45 | #include <stdio_dev.h> |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 46 | #include <post.h> |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 47 | #include <logbuff.h> |
| 48 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 49 | DECLARE_GLOBAL_DATA_PTR; |
| 50 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 51 | /* Local prototypes */ |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 52 | static void logbuff_putc(const char c); |
| 53 | static void logbuff_puts(const char *s); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 54 | static int logbuff_printk(const char *line); |
| 55 | |
| 56 | static char buf[1024]; |
| 57 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 58 | /* This combination will not print messages with the default loglevel */ |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 59 | static unsigned console_loglevel = 3; |
| 60 | static unsigned default_message_loglevel = 4; |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 61 | static unsigned log_version = 1; |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 62 | #ifdef CONFIG_ALT_LB_ADDR |
| 63 | static volatile logbuff_t *log; |
| 64 | #else |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 65 | static logbuff_t *log; |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 66 | #endif |
| 67 | static char *lbuf; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 68 | |
Marian Balakowicz | 95d449a | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 69 | unsigned long __logbuffer_base(void) |
| 70 | { |
Heiko Schocher | ee4014b | 2011-10-12 01:13:38 +0000 | [diff] [blame] | 71 | return CONFIG_SYS_SDRAM_BASE + gd->ram_size - LOGBUFF_LEN; |
Marian Balakowicz | 95d449a | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 72 | } |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 73 | unsigned long logbuffer_base(void) |
| 74 | __attribute__((weak, alias("__logbuffer_base"))); |
Marian Balakowicz | 95d449a | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 75 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 76 | void logbuff_init_ptrs(void) |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 77 | { |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 78 | unsigned long tag, post_word; |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 79 | char *s; |
| 80 | |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 81 | #ifdef CONFIG_ALT_LB_ADDR |
| 82 | log = (logbuff_t *)CONFIG_ALT_LH_ADDR; |
| 83 | lbuf = (char *)CONFIG_ALT_LB_ADDR; |
| 84 | #else |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 85 | log = (logbuff_t *)(logbuffer_base()) - 1; |
Jean-Christophe PLAGNIOL-VILLARD | a253b38 | 2008-04-02 08:03:57 +0200 | [diff] [blame] | 86 | lbuf = (char *)log->buf; |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 87 | #endif |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 88 | |
| 89 | /* Set up log version */ |
| 90 | if ((s = getenv ("logversion")) != NULL) |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 91 | log_version = (int)simple_strtoul(s, NULL, 10); |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 92 | |
| 93 | if (log_version == 2) |
| 94 | tag = log->v2.tag; |
| 95 | else |
| 96 | tag = log->v1.tag; |
wdenk | 2960b65 | 2003-07-15 21:08:26 +0000 | [diff] [blame] | 97 | post_word = post_word_load(); |
wdenk | d1cbe85 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 98 | #ifdef CONFIG_POST |
| 99 | /* The post routines have setup the word so we can simply test it */ |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 100 | if (tag != LOGBUFF_MAGIC || (post_word & POST_COLDBOOT)) |
| 101 | logbuff_reset(); |
wdenk | d1cbe85 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 102 | #else |
| 103 | /* No post routines, so we do our own checking */ |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 104 | if (tag != LOGBUFF_MAGIC || post_word != LOGBUFF_MAGIC) { |
| 105 | logbuff_reset (); |
wdenk | d1cbe85 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 106 | post_word_store (LOGBUFF_MAGIC); |
Wolfgang Denk | 1636d1c | 2007-06-22 23:59:00 +0200 | [diff] [blame] | 107 | } |
wdenk | d1cbe85 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 108 | #endif |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 109 | if (log_version == 2 && (long)log->v2.start > (long)log->v2.con) |
| 110 | log->v2.start = log->v2.con; |
| 111 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 112 | /* Initialize default loglevel if present */ |
| 113 | if ((s = getenv ("loglevel")) != NULL) |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 114 | console_loglevel = (int)simple_strtoul(s, NULL, 10); |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 115 | |
Yuri Tikhonov | 0e15ddd | 2008-05-08 15:46:42 +0200 | [diff] [blame] | 116 | gd->flags |= GD_FLG_LOGINIT; |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 119 | void logbuff_reset(void) |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 120 | { |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 121 | #ifndef CONFIG_ALT_LB_ADDR |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 122 | memset(log, 0, sizeof(logbuff_t)); |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 123 | #endif |
| 124 | if (log_version == 2) { |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 125 | log->v2.tag = LOGBUFF_MAGIC; |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 126 | #ifdef CONFIG_ALT_LB_ADDR |
| 127 | log->v2.start = 0; |
| 128 | log->v2.con = 0; |
| 129 | log->v2.end = 0; |
| 130 | log->v2.chars = 0; |
| 131 | #endif |
| 132 | } else { |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 133 | log->v1.tag = LOGBUFF_MAGIC; |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 134 | #ifdef CONFIG_ALT_LB_ADDR |
| 135 | log->v1.dummy = 0; |
| 136 | log->v1.start = 0; |
| 137 | log->v1.size = 0; |
| 138 | log->v1.chars = 0; |
| 139 | #endif |
| 140 | } |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 141 | } |
| 142 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 143 | int drv_logbuff_init(void) |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 144 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 145 | struct stdio_dev logdev; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 146 | int rc; |
| 147 | |
| 148 | /* Device initialization */ |
| 149 | memset (&logdev, 0, sizeof (logdev)); |
| 150 | |
| 151 | strcpy (logdev.name, "logbuff"); |
| 152 | logdev.ext = 0; /* No extensions */ |
| 153 | logdev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
| 154 | logdev.putc = logbuff_putc; /* 'putc' function */ |
| 155 | logdev.puts = logbuff_puts; /* 'puts' function */ |
| 156 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 157 | rc = stdio_register(&logdev); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 158 | |
| 159 | return (rc == 0) ? 1 : rc; |
| 160 | } |
| 161 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 162 | static void logbuff_putc(const char c) |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 163 | { |
| 164 | char buf[2]; |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 165 | buf[0] = c; |
| 166 | buf[1] = '\0'; |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 167 | logbuff_printk(buf); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 170 | static void logbuff_puts(const char *s) |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 171 | { |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 172 | logbuff_printk (s); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | void logbuff_log(char *msg) |
| 176 | { |
Yuri Tikhonov | 0e15ddd | 2008-05-08 15:46:42 +0200 | [diff] [blame] | 177 | if ((gd->flags & GD_FLG_LOGINIT)) { |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 178 | logbuff_printk(msg); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 179 | } else { |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 180 | /* |
| 181 | * Can happen only for pre-relocated errors as logging |
| 182 | * at that stage should be disabled |
| 183 | */ |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 184 | puts (msg); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * Subroutine: do_log |
| 190 | * |
| 191 | * Description: Handler for 'log' command.. |
| 192 | * |
| 193 | * Inputs: argv[1] contains the subcommand |
| 194 | * |
| 195 | * Return: None |
| 196 | * |
| 197 | */ |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 198 | int do_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 199 | { |
| 200 | char *s; |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 201 | unsigned long i, start, size; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 202 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 203 | if (strcmp(argv[1], "append") == 0) { |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 204 | /* Log concatenation of all arguments separated by spaces */ |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 205 | for (i = 2; i < argc; i++) { |
| 206 | logbuff_printk(argv[i]); |
| 207 | logbuff_putc((i < argc - 1) ? ' ' : '\n'); |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 208 | } |
| 209 | return 0; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | switch (argc) { |
| 213 | |
| 214 | case 2: |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 215 | if (strcmp(argv[1], "show") == 0) { |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 216 | if (log_version == 2) { |
| 217 | start = log->v2.start; |
| 218 | size = log->v2.end - log->v2.start; |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 219 | } else { |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 220 | start = log->v1.start; |
| 221 | size = log->v1.size; |
| 222 | } |
Heiko Schocher | c16a123 | 2012-02-16 01:02:21 +0000 | [diff] [blame] | 223 | if (size > LOGBUFF_LEN) |
| 224 | size = LOGBUFF_LEN; |
| 225 | for (i = 0; i < size; i++) { |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 226 | s = lbuf + ((start + i) & LOGBUFF_MASK); |
| 227 | putc(*s); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 228 | } |
| 229 | return 0; |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 230 | } else if (strcmp(argv[1], "reset") == 0) { |
| 231 | logbuff_reset(); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 232 | return 0; |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 233 | } else if (strcmp(argv[1], "info") == 0) { |
| 234 | printf("Logbuffer at %08lx\n", (unsigned long)lbuf); |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 235 | if (log_version == 2) { |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 236 | printf("log_start = %08lx\n", |
| 237 | log->v2.start); |
| 238 | printf("log_end = %08lx\n", log->v2.end); |
Heiko Schocher | c0b77e0 | 2012-02-14 22:21:07 +0000 | [diff] [blame^] | 239 | printf("log_con = %08lx\n", log->v2.con); |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 240 | printf("logged_chars = %08lx\n", |
| 241 | log->v2.chars); |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 242 | } |
| 243 | else { |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 244 | printf("log_start = %08lx\n", |
| 245 | log->v1.start); |
| 246 | printf("log_size = %08lx\n", |
| 247 | log->v1.size); |
| 248 | printf("logged_chars = %08lx\n", |
| 249 | log->v1.chars); |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 250 | } |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 251 | return 0; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 252 | } |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 253 | return CMD_RET_USAGE; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 254 | |
| 255 | default: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 256 | return CMD_RET_USAGE; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 257 | } |
| 258 | } |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 259 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 260 | U_BOOT_CMD( |
| 261 | log, 255, 1, do_log, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 262 | "manipulate logbuffer", |
wdenk | b37c7e5 | 2003-06-30 16:24:52 +0000 | [diff] [blame] | 263 | "info - show pointer details\n" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 264 | "log reset - clear contents\n" |
| 265 | "log show - show contents\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 266 | "log append <msg> - append <msg> to the logbuffer" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 267 | ); |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 268 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 269 | static int logbuff_printk(const char *line) |
| 270 | { |
| 271 | int i; |
| 272 | char *msg, *p, *buf_end; |
| 273 | int line_feed; |
| 274 | static signed char msg_level = -1; |
| 275 | |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 276 | strcpy(buf + 3, line); |
| 277 | i = strlen(line); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 278 | buf_end = buf + 3 + i; |
| 279 | for (p = buf + 3; p < buf_end; p++) { |
| 280 | msg = p; |
| 281 | if (msg_level < 0) { |
| 282 | if ( |
| 283 | p[0] != '<' || |
| 284 | p[1] < '0' || |
| 285 | p[1] > '7' || |
| 286 | p[2] != '>' |
| 287 | ) { |
| 288 | p -= 3; |
| 289 | p[0] = '<'; |
| 290 | p[1] = default_message_loglevel + '0'; |
| 291 | p[2] = '>'; |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 292 | } else { |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 293 | msg += 3; |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 294 | } |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 295 | msg_level = p[1] - '0'; |
| 296 | } |
| 297 | line_feed = 0; |
| 298 | for (; p < buf_end; p++) { |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 299 | if (log_version == 2) { |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 300 | lbuf[log->v2.end & LOGBUFF_MASK] = *p; |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 301 | log->v2.end++; |
| 302 | if (log->v2.end - log->v2.start > LOGBUFF_LEN) |
| 303 | log->v2.start++; |
| 304 | log->v2.chars++; |
Heiko Schocher | 1e8e7ae | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 305 | } else { |
Yuri Tikhonov | 3d61018 | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 306 | lbuf[(log->v1.start + log->v1.size) & |
Igor Lisitsin | 2dc6445 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 307 | LOGBUFF_MASK] = *p; |
| 308 | if (log->v1.size < LOGBUFF_LEN) |
| 309 | log->v1.size++; |
| 310 | else |
| 311 | log->v1.start++; |
| 312 | log->v1.chars++; |
| 313 | } |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 314 | if (*p == '\n') { |
| 315 | line_feed = 1; |
| 316 | break; |
| 317 | } |
| 318 | } |
| 319 | if (msg_level < console_loglevel) { |
| 320 | printf("%s", msg); |
| 321 | } |
| 322 | if (line_feed) |
| 323 | msg_level = -1; |
| 324 | } |
| 325 | return i; |
| 326 | } |