author | mockner |
Wed, 03 Feb 2016 11:40:30 -0500 | |
changeset 35917 | 463d67f86eaa |
parent 34316 | 4d876653d940 |
permissions | -rw-r--r-- |
33097 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
#include "precompiled.hpp" |
|
25 |
#include "logging/logDecorators.hpp" |
|
26 |
#include "runtime/os.inline.hpp" |
|
27 |
||
34316
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
28 |
const LogDecorators LogDecorators::None = LogDecorators(0); |
4d876653d940
8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents:
33097
diff
changeset
|
29 |
|
33097 | 30 |
const char* LogDecorators::_name[][2] = { |
31 |
#define DECORATOR(n, a) {#n, #a}, |
|
32 |
DECORATOR_LIST |
|
33 |
#undef DECORATOR |
|
34 |
}; |
|
35 |
||
36 |
LogDecorators::Decorator LogDecorators::from_string(const char* str) { |
|
37 |
for (size_t i = 0; i < Count; i++) { |
|
38 |
Decorator d = static_cast<Decorator>(i); |
|
39 |
if (strcasecmp(str, name(d)) == 0 || strcasecmp(str, abbreviation(d)) == 0) { |
|
40 |
return d; |
|
41 |
} |
|
42 |
} |
|
43 |
return Invalid; |
|
44 |
} |
|
45 |
||
46 |
bool LogDecorators::parse(const char* decorator_args, outputStream* errstream) { |
|
47 |
if (decorator_args == NULL || strlen(decorator_args) == 0) { |
|
48 |
_decorators = DefaultDecoratorsMask; |
|
49 |
return true; |
|
50 |
} |
|
51 |
||
52 |
if (strcasecmp(decorator_args, "none") == 0 ) { |
|
53 |
_decorators = 0; |
|
54 |
return true; |
|
55 |
} |
|
56 |
||
57 |
bool result = true; |
|
58 |
uint tmp_decorators = 0; |
|
59 |
char* args_copy = os::strdup_check_oom(decorator_args, mtLogging); |
|
60 |
char* token = args_copy; |
|
61 |
char* comma_pos; |
|
62 |
do { |
|
63 |
comma_pos = strchr(token, ','); |
|
64 |
if (comma_pos != NULL) { |
|
65 |
*comma_pos = '\0'; |
|
66 |
} |
|
67 |
Decorator d = from_string(token); |
|
68 |
if (d == Invalid) { |
|
69 |
if (errstream != NULL) { |
|
70 |
errstream->print_cr("Invalid decorator '%s'.", token); |
|
71 |
} |
|
72 |
result = false; |
|
73 |
break; |
|
74 |
} |
|
75 |
tmp_decorators |= mask(d); |
|
76 |
token = comma_pos + 1; |
|
77 |
} while (comma_pos != NULL); |
|
78 |
os::free(args_copy); |
|
79 |
if (result) { |
|
80 |
_decorators = tmp_decorators; |
|
81 |
} |
|
82 |
return result; |
|
83 |
} |