wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 1 | /* |
Igor Lisitsin | 93470f2 | 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 | 9dfa8d1 | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 9 | * |
| 10 | * Comments: |
| 11 | * |
| 12 | * After relocating the code, the environment variable "loglevel" is |
| 13 | * copied to console_loglevel. The functionality is similar to the |
| 14 | * handling in the Linux kernel, i.e. messages logged with a priority |
| 15 | * less than console_loglevel are also output to stdout. |
| 16 | * |
| 17 | * If you want messages with the default level (e.g. POST messages) to |
| 18 | * appear on stdout also, make sure the environment variable |
| 19 | * "loglevel" is set at boot time to a number higher than |
| 20 | * default_message_loglevel below. |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * Logbuffer handling routines |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 29 | #include <stdio_dev.h> |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 30 | #include <post.h> |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 31 | #include <logbuff.h> |
| 32 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 35 | /* Local prototypes */ |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 36 | static void logbuff_putc(struct stdio_dev *dev, const char c); |
| 37 | static void logbuff_puts(struct stdio_dev *dev, const char *s); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 38 | static int logbuff_printk(const char *line); |
| 39 | |
| 40 | static char buf[1024]; |
| 41 | |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 42 | /* This combination will not print messages with the default loglevel */ |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 43 | static unsigned console_loglevel = 3; |
| 44 | static unsigned default_message_loglevel = 4; |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 45 | static unsigned log_version = 1; |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 46 | #ifdef CONFIG_ALT_LB_ADDR |
| 47 | static volatile logbuff_t *log; |
| 48 | #else |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 49 | static logbuff_t *log; |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 50 | #endif |
| 51 | static char *lbuf; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 52 | |
Marian Balakowicz | 902ce70 | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 53 | unsigned long __logbuffer_base(void) |
| 54 | { |
York Sun | 863e8d8 | 2014-02-11 11:57:26 -0800 | [diff] [blame] | 55 | return CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - LOGBUFF_LEN; |
Marian Balakowicz | 902ce70 | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 56 | } |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 57 | unsigned long logbuffer_base(void) |
| 58 | __attribute__((weak, alias("__logbuffer_base"))); |
Marian Balakowicz | 902ce70 | 2008-05-13 15:53:29 +0200 | [diff] [blame] | 59 | |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 60 | void logbuff_init_ptrs(void) |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 61 | { |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 62 | unsigned long tag, post_word; |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 63 | char *s; |
| 64 | |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 65 | #ifdef CONFIG_ALT_LB_ADDR |
| 66 | log = (logbuff_t *)CONFIG_ALT_LH_ADDR; |
| 67 | lbuf = (char *)CONFIG_ALT_LB_ADDR; |
| 68 | #else |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 69 | log = (logbuff_t *)(logbuffer_base()) - 1; |
Jean-Christophe PLAGNIOL-VILLARD | 531ad56 | 2008-04-02 08:03:57 +0200 | [diff] [blame] | 70 | lbuf = (char *)log->buf; |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 71 | #endif |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 72 | |
| 73 | /* Set up log version */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 74 | s = env_get("logversion"); |
| 75 | if (s) |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 76 | log_version = (int)simple_strtoul(s, NULL, 10); |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 77 | |
| 78 | if (log_version == 2) |
| 79 | tag = log->v2.tag; |
| 80 | else |
| 81 | tag = log->v1.tag; |
wdenk | 41bea11 | 2003-07-15 21:08:26 +0000 | [diff] [blame] | 82 | post_word = post_word_load(); |
wdenk | d9fce81 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 83 | #ifdef CONFIG_POST |
| 84 | /* The post routines have setup the word so we can simply test it */ |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 85 | if (tag != LOGBUFF_MAGIC || (post_word & POST_COLDBOOT)) |
| 86 | logbuff_reset(); |
wdenk | d9fce81 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 87 | #else |
| 88 | /* No post routines, so we do our own checking */ |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 89 | if (tag != LOGBUFF_MAGIC || post_word != LOGBUFF_MAGIC) { |
| 90 | logbuff_reset (); |
wdenk | d9fce81 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 91 | post_word_store (LOGBUFF_MAGIC); |
Wolfgang Denk | 70df7bc | 2007-06-22 23:59:00 +0200 | [diff] [blame] | 92 | } |
wdenk | d9fce81 | 2003-06-28 17:24:46 +0000 | [diff] [blame] | 93 | #endif |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 94 | if (log_version == 2 && (long)log->v2.start > (long)log->v2.con) |
| 95 | log->v2.start = log->v2.con; |
| 96 | |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 97 | /* Initialize default loglevel if present */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 98 | s = env_get("loglevel"); |
| 99 | if (s) |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 100 | console_loglevel = (int)simple_strtoul(s, NULL, 10); |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 101 | |
Yuri Tikhonov | 35d81ce | 2008-05-08 15:46:42 +0200 | [diff] [blame] | 102 | gd->flags |= GD_FLG_LOGINIT; |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 105 | void logbuff_reset(void) |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 106 | { |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 107 | #ifndef CONFIG_ALT_LB_ADDR |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 108 | memset(log, 0, sizeof(logbuff_t)); |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 109 | #endif |
| 110 | if (log_version == 2) { |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 111 | log->v2.tag = LOGBUFF_MAGIC; |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 112 | #ifdef CONFIG_ALT_LB_ADDR |
| 113 | log->v2.start = 0; |
| 114 | log->v2.con = 0; |
| 115 | log->v2.end = 0; |
| 116 | log->v2.chars = 0; |
| 117 | #endif |
| 118 | } else { |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 119 | log->v1.tag = LOGBUFF_MAGIC; |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 120 | #ifdef CONFIG_ALT_LB_ADDR |
| 121 | log->v1.dummy = 0; |
| 122 | log->v1.start = 0; |
| 123 | log->v1.size = 0; |
| 124 | log->v1.chars = 0; |
| 125 | #endif |
| 126 | } |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 127 | } |
| 128 | |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 129 | int drv_logbuff_init(void) |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 130 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 131 | struct stdio_dev logdev; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 132 | int rc; |
| 133 | |
| 134 | /* Device initialization */ |
| 135 | memset (&logdev, 0, sizeof (logdev)); |
| 136 | |
| 137 | strcpy (logdev.name, "logbuff"); |
| 138 | logdev.ext = 0; /* No extensions */ |
| 139 | logdev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
| 140 | logdev.putc = logbuff_putc; /* 'putc' function */ |
| 141 | logdev.puts = logbuff_puts; /* 'puts' function */ |
| 142 | |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 143 | rc = stdio_register(&logdev); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 144 | |
| 145 | return (rc == 0) ? 1 : rc; |
| 146 | } |
| 147 | |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 148 | static void logbuff_putc(struct stdio_dev *dev, const char c) |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 149 | { |
| 150 | char buf[2]; |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 151 | buf[0] = c; |
| 152 | buf[1] = '\0'; |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 153 | logbuff_printk(buf); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 156 | static void logbuff_puts(struct stdio_dev *dev, const char *s) |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 157 | { |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 158 | logbuff_printk (s); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void logbuff_log(char *msg) |
| 162 | { |
Yuri Tikhonov | 35d81ce | 2008-05-08 15:46:42 +0200 | [diff] [blame] | 163 | if ((gd->flags & GD_FLG_LOGINIT)) { |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 164 | logbuff_printk(msg); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 165 | } else { |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 166 | /* |
| 167 | * Can happen only for pre-relocated errors as logging |
| 168 | * at that stage should be disabled |
| 169 | */ |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 170 | puts (msg); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 174 | /* |
| 175 | * Subroutine: do_log |
| 176 | * |
| 177 | * Description: Handler for 'log' command.. |
| 178 | * |
| 179 | * Inputs: argv[1] contains the subcommand |
| 180 | * |
| 181 | * Return: None |
| 182 | * |
| 183 | */ |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 184 | 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] | 185 | { |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 186 | struct stdio_dev *sdev = NULL; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 187 | char *s; |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 188 | unsigned long i, start, size; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 189 | |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 190 | if (strcmp(argv[1], "append") == 0) { |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 191 | /* Log concatenation of all arguments separated by spaces */ |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 192 | for (i = 2; i < argc; i++) { |
| 193 | logbuff_printk(argv[i]); |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 194 | logbuff_putc(sdev, (i < argc - 1) ? ' ' : '\n'); |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 195 | } |
| 196 | return 0; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | switch (argc) { |
| 200 | |
| 201 | case 2: |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 202 | if (strcmp(argv[1], "show") == 0) { |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 203 | if (log_version == 2) { |
| 204 | start = log->v2.start; |
| 205 | size = log->v2.end - log->v2.start; |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 206 | } else { |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 207 | start = log->v1.start; |
| 208 | size = log->v1.size; |
| 209 | } |
Heiko Schocher | e5f7869 | 2012-02-16 01:02:21 +0000 | [diff] [blame] | 210 | if (size > LOGBUFF_LEN) |
| 211 | size = LOGBUFF_LEN; |
| 212 | for (i = 0; i < size; i++) { |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 213 | s = lbuf + ((start + i) & LOGBUFF_MASK); |
| 214 | putc(*s); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 215 | } |
| 216 | return 0; |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 217 | } else if (strcmp(argv[1], "reset") == 0) { |
| 218 | logbuff_reset(); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 219 | return 0; |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 220 | } else if (strcmp(argv[1], "info") == 0) { |
| 221 | printf("Logbuffer at %08lx\n", (unsigned long)lbuf); |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 222 | if (log_version == 2) { |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 223 | printf("log_start = %08lx\n", |
| 224 | log->v2.start); |
| 225 | printf("log_end = %08lx\n", log->v2.end); |
Heiko Schocher | 650ebc0 | 2012-02-14 22:21:07 +0000 | [diff] [blame] | 226 | printf("log_con = %08lx\n", log->v2.con); |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 227 | printf("logged_chars = %08lx\n", |
| 228 | log->v2.chars); |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 229 | } |
| 230 | else { |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 231 | printf("log_start = %08lx\n", |
| 232 | log->v1.start); |
| 233 | printf("log_size = %08lx\n", |
| 234 | log->v1.size); |
| 235 | printf("logged_chars = %08lx\n", |
| 236 | log->v1.chars); |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 237 | } |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 238 | return 0; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 239 | } |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 240 | return CMD_RET_USAGE; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 241 | |
| 242 | default: |
Simon Glass | a06dfc7 | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 243 | return CMD_RET_USAGE; |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 246 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 247 | U_BOOT_CMD( |
| 248 | log, 255, 1, do_log, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 249 | "manipulate logbuffer", |
wdenk | b9bbd24 | 2003-06-30 16:24:52 +0000 | [diff] [blame] | 250 | "info - show pointer details\n" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 251 | "log reset - clear contents\n" |
| 252 | "log show - show contents\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 253 | "log append <msg> - append <msg> to the logbuffer" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 254 | ); |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 255 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 256 | static int logbuff_printk(const char *line) |
| 257 | { |
| 258 | int i; |
| 259 | char *msg, *p, *buf_end; |
| 260 | int line_feed; |
| 261 | static signed char msg_level = -1; |
| 262 | |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 263 | strcpy(buf + 3, line); |
| 264 | i = strlen(line); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 265 | buf_end = buf + 3 + i; |
| 266 | for (p = buf + 3; p < buf_end; p++) { |
| 267 | msg = p; |
| 268 | if (msg_level < 0) { |
| 269 | if ( |
| 270 | p[0] != '<' || |
| 271 | p[1] < '0' || |
| 272 | p[1] > '7' || |
| 273 | p[2] != '>' |
| 274 | ) { |
| 275 | p -= 3; |
| 276 | p[0] = '<'; |
| 277 | p[1] = default_message_loglevel + '0'; |
| 278 | p[2] = '>'; |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 279 | } else { |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 280 | msg += 3; |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 281 | } |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 282 | msg_level = p[1] - '0'; |
| 283 | } |
| 284 | line_feed = 0; |
| 285 | for (; p < buf_end; p++) { |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 286 | if (log_version == 2) { |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 287 | lbuf[log->v2.end & LOGBUFF_MASK] = *p; |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 288 | log->v2.end++; |
| 289 | if (log->v2.end - log->v2.start > LOGBUFF_LEN) |
| 290 | log->v2.start++; |
| 291 | log->v2.chars++; |
Heiko Schocher | 3102012 | 2012-02-14 22:21:06 +0000 | [diff] [blame] | 292 | } else { |
Yuri Tikhonov | fe1d91b | 2008-02-06 18:48:36 +0100 | [diff] [blame] | 293 | lbuf[(log->v1.start + log->v1.size) & |
Igor Lisitsin | 93470f2 | 2007-04-18 14:55:19 +0400 | [diff] [blame] | 294 | LOGBUFF_MASK] = *p; |
| 295 | if (log->v1.size < LOGBUFF_LEN) |
| 296 | log->v1.size++; |
| 297 | else |
| 298 | log->v1.start++; |
| 299 | log->v1.chars++; |
| 300 | } |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 301 | if (*p == '\n') { |
| 302 | line_feed = 1; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | if (msg_level < console_loglevel) { |
| 307 | printf("%s", msg); |
| 308 | } |
| 309 | if (line_feed) |
| 310 | msg_level = -1; |
| 311 | } |
| 312 | return i; |
| 313 | } |