1b8a72a62Sopenharmony_ci/*
2b8a72a62Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3b8a72a62Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b8a72a62Sopenharmony_ci * you may not use this file except in compliance with the License.
5b8a72a62Sopenharmony_ci * You may obtain a copy of the License at
6b8a72a62Sopenharmony_ci *
7b8a72a62Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b8a72a62Sopenharmony_ci *
9b8a72a62Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b8a72a62Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b8a72a62Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b8a72a62Sopenharmony_ci * See the License for the specific language governing permissions and
13b8a72a62Sopenharmony_ci * limitations under the License.
14b8a72a62Sopenharmony_ci */
15b8a72a62Sopenharmony_cipackage ohos;
16b8a72a62Sopenharmony_ci
17b8a72a62Sopenharmony_ciimport java.text.DateFormat;
18b8a72a62Sopenharmony_ciimport java.text.SimpleDateFormat;
19b8a72a62Sopenharmony_ciimport java.util.Date;
20b8a72a62Sopenharmony_ciimport java.util.logging.Formatter;
21b8a72a62Sopenharmony_ciimport java.util.logging.LogRecord;
22b8a72a62Sopenharmony_ci
23b8a72a62Sopenharmony_ci/**
24b8a72a62Sopenharmony_ci * Pack for matter
25b8a72a62Sopenharmony_ci *
26b8a72a62Sopenharmony_ci */
27b8a72a62Sopenharmony_cipublic class PackFormatter extends Formatter {
28b8a72a62Sopenharmony_ci    private static final int LOG_MAX_LIMIT = 1000;
29b8a72a62Sopenharmony_ci    private static final DateFormat DF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
30b8a72a62Sopenharmony_ci
31b8a72a62Sopenharmony_ci    @Override
32b8a72a62Sopenharmony_ci
33b8a72a62Sopenharmony_ci    /**
34b8a72a62Sopenharmony_ci     * format builder
35b8a72a62Sopenharmony_ci     *
36b8a72a62Sopenharmony_ci     * @param Log limit size
37b8a72a62Sopenharmony_ci     * @return string builder
38b8a72a62Sopenharmony_ci     */
39b8a72a62Sopenharmony_ci    public String format(LogRecord record) {
40b8a72a62Sopenharmony_ci        StringBuilder builder = new StringBuilder(LOG_MAX_LIMIT);
41b8a72a62Sopenharmony_ci        builder.append(DF.format(new Date(record.getMillis()))).append(" - ");
42b8a72a62Sopenharmony_ci        builder.append(formatMessage(record));
43b8a72a62Sopenharmony_ci        builder.append(System.lineSeparator());
44b8a72a62Sopenharmony_ci        return builder.toString();
45b8a72a62Sopenharmony_ci    }
46b8a72a62Sopenharmony_ci}