3 * Copyright (c) 2013 Thomas Perl <m@thp.io>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
27 FILE *hybris_logging_target
= NULL
;
29 pthread_mutex_t hybris_logging_mutex
;
31 static enum hybris_log_level
32 hybris_minimum_log_level
= HYBRIS_LOG_WARN
;
34 static enum hybris_log_format _hybris_logging_format
= HYBRIS_LOG_FORMAT_NORMAL
;
36 static int _hybris_should_trace
= 0;
39 hybris_logging_initialized
= 0;
42 hybris_logging_initialize()
44 const char *env
= getenv("HYBRIS_LOGGING_LEVEL");
47 /* Nothing to do - use default level */
48 } else if (strcmp(env
, "debug") == 0) {
49 hybris_minimum_log_level
= HYBRIS_LOG_DEBUG
;
50 } else if (strcmp(env
, "info") == 0) {
51 hybris_minimum_log_level
= HYBRIS_LOG_INFO
;
52 } else if (strcmp(env
, "warn") == 0) {
53 hybris_minimum_log_level
= HYBRIS_LOG_WARN
;
54 } else if (strcmp(env
, "error") == 0) {
55 hybris_minimum_log_level
= HYBRIS_LOG_ERROR
;
56 } else if (strcmp(env
, "disabled") == 0) {
57 hybris_minimum_log_level
= HYBRIS_LOG_DISABLED
;
60 env
= getenv("HYBRIS_LOGGING_TARGET");
63 hybris_logging_target
= fopen(env
, "a");
65 if (hybris_logging_target
== NULL
)
66 hybris_logging_target
= stderr
;
68 env
= getenv("HYBRIS_LOGGING_FORMAT");
71 if (strcmp(env
, "systrace") == 0) {
72 _hybris_logging_format
= HYBRIS_LOG_FORMAT_SYSTRACE
;
75 _hybris_logging_format
= HYBRIS_LOG_FORMAT_NORMAL
;
78 env
= getenv("HYBRIS_TRACE");
81 if (strcmp(env
, "1") == 0) {
82 _hybris_should_trace
= 1;
85 pthread_mutex_init(&hybris_logging_mutex
, NULL
);
89 hybris_should_log(enum hybris_log_level level
)
91 /* Initialize logging level from environment */
92 if (!hybris_logging_initialized
) {
93 hybris_logging_initialized
= 1;
94 hybris_logging_initialize();
97 return (level
>= hybris_minimum_log_level
);
101 hybris_set_log_level(enum hybris_log_level level
)
103 hybris_minimum_log_level
= level
;
107 hybris_get_thread_id()
109 return (void *)pthread_self();
113 hybris_should_trace(const char *module
, const char *tracepoint
)
115 return _hybris_should_trace
;
118 enum hybris_log_format
hybris_logging_format()
120 return _hybris_logging_format
;