2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dlog-redirect-stdout.h>
25 /* We send two messages on the main buffer and one on the system buffer.
26 * Each message has a different priority and tag. This allows us to make sure
27 * all the parameters can be changed by reconnecting. Additionally,
28 * sending two of the messages on the same buffer allows us to check
29 * if the message order is correct. */
31 /* NB: The flushes are needed here. This is because stdout is buffered.
32 * If we don't flush, it will only actually do the write syscalls at the end
33 * of the program execution. Therefore, all the logs will be written to the
34 * last connection. Note that libdlog tries to mitigate that, but this binary
35 * is not linked to libdlog, and the mitigation is a best-effort hack anyway. */
36 if (dlog_connect_fd(LOG_ID_MAIN, STDOUT_FILENO, "TAG1", DLOG_WARN) < 0)
40 if (dlog_connect_fd(LOG_ID_MAIN, STDOUT_FILENO, "TAG2", DLOG_ERROR) < 0)
44 if (dlog_connect_fd(LOG_ID_SYSTEM, STDOUT_FILENO, "TAG3", DLOG_INFO) < 0)